diff --git a/.goreleaser.yml b/.goreleaser.yml index 8774a82da..98a9c6cc0 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -16,7 +16,7 @@ builds: goarm: - "6" main: . - ldflags: -s -w -X github.com/astronomerio/astro-cli/cmd.currVersion={{ .Version }} -X github.com/astronomerio/astro-cli/cmd.currCommit={{ .Commit }} + ldflags: -s -w -X github.com/astronomerio/astro-cli/version.CurrVersion={{ .Version }} -X github.com/astronomerio/astro-cli/version.CurrCommit={{ .Commit }} binary: astro ignore: - goos: windows diff --git a/Makefile b/Makefile index 3accc7816..852227846 100644 --- a/Makefile +++ b/Makefile @@ -4,8 +4,8 @@ GIT_COMMIT=$(shell git rev-parse HEAD) GIT_COMMIT_SHORT=$(shell git rev-parse --short HEAD) VERSION ?= SNAPSHOT-${GIT_COMMIT_SHORT} -LDFLAGS_VERSION=-X github.com/astronomer/astro-cli/cmd.currVersion=${VERSION} -LDFLAGS_GIT_COMMIT=-X github.com/astronomer/astro-cli/cmd.currCommit=${GIT_COMMIT} +LDFLAGS_VERSION=-X github.com/astronomer/astro-cli/version.CurrVersion=${VERSION} +LDFLAGS_GIT_COMMIT=-X github.com/astronomer/astro-cli/version.CurrCommit=${GIT_COMMIT} .DEFAULT_GOAL := build diff --git a/airflow/airflow.go b/airflow/airflow.go index 45a55184b..3b8632a0c 100644 --- a/airflow/airflow.go +++ b/airflow/airflow.go @@ -1,6 +1,7 @@ package airflow import ( + "fmt" "os" "path/filepath" "regexp" @@ -13,6 +14,7 @@ import ( "github.com/astronomer/astro-cli/airflow/include" "github.com/astronomer/astro-cli/messages" "github.com/astronomer/astro-cli/pkg/fileutil" + "github.com/astronomer/astro-cli/version" ) func initDirs(root string, dirs []string) error { @@ -68,8 +70,9 @@ func Init(path string) error { // Map of files to create files := map[string]string{ - ".dockerignore": include.Dockerignore, - "Dockerfile": include.Dockerfile, + ".dockerignore": include.Dockerignore, + "Dockerfile": fmt.Sprintf(include.Dockerfile, + version.GetTagFromVersion()), "packages.txt": "", "requirements.txt": "", "dags/example-dag.py": include.Exampledag, diff --git a/airflow/include/dockerfile.go b/airflow/include/dockerfile.go index 03b10e2d1..d059cc063 100644 --- a/airflow/include/dockerfile.go +++ b/airflow/include/dockerfile.go @@ -4,5 +4,5 @@ import "strings" // Dockerfile is the Dockerfile template var Dockerfile = strings.TrimSpace(` -FROM astronomerinc/ap-airflow:latest-onbuild +FROM astronomerinc/ap-airflow:%s `) diff --git a/cmd/version.go b/cmd/version.go index 366816eb2..faff5dc69 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -6,9 +6,7 @@ import ( ) var ( - currVersion string - currCommit string - versionCmd = &cobra.Command{ + versionCmd = &cobra.Command{ Use: "version", Short: "Astronomer CLI version", Long: "The astro-cli semantic version and git commit tied to that release.", @@ -32,7 +30,7 @@ func printVersion(cmd *cobra.Command, args []string) error { // Silence Usage as we have now validated command input cmd.SilenceUsage = true - err := version.PrintVersion(currVersion, currCommit) + err := version.PrintVersion() if err != nil { return err } @@ -43,7 +41,7 @@ func upgradeCheck(cmd *cobra.Command, args []string) error { // Silence Usage as we have now validated command input cmd.SilenceUsage = true - err := version.CheckForUpdate(currVersion, currCommit) + err := version.CheckForUpdate() if err != nil { return err } diff --git a/version/version.go b/version/version.go index 5719f1774..93b4b2334 100644 --- a/version/version.go +++ b/version/version.go @@ -3,17 +3,23 @@ package version import ( "errors" "fmt" + s "strings" "github.com/astronomer/astro-cli/messages" "github.com/astronomer/astro-cli/pkg/github" ) var ( - api = github.NewGithubClient() + CurrVersion string + CurrCommit string + api = github.NewGithubClient() ) // PrintVersion outputs current cli version and git commit if exists -func PrintVersion(version, gitCommit string) error { +func PrintVersion() error { + version := CurrVersion + gitCommit := CurrCommit + if !isValidVersion(version) { return errors.New(messages.ERROR_INVALID_CLI_VERSION) } @@ -24,7 +30,9 @@ func PrintVersion(version, gitCommit string) error { } // CheckForUpdate checks current version against latest on github -func CheckForUpdate(version, gitCommit string) error { +func CheckForUpdate() error { + version := CurrVersion + if !isValidVersion(version) { fmt.Println(messages.CLI_UNTAGGED_PROMPT) fmt.Println(messages.CLI_INSTALL_CMD) @@ -70,3 +78,13 @@ func isValidVersion(version string) bool { } return true } + +func GetTagFromVersion() string { + version := CurrVersion + + if !isValidVersion(version) || s.HasPrefix(version, "SNAPSHOT-") { + return "master-onbuild-1.9.0" + } else { + return fmt.Sprintf("%s-%s-onbuild", version, "1.9.0") + } +}