Skip to content

Commit

Permalink
Anchor dockerfile tag to platform version (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
andscoop authored Nov 28, 2018
1 parent acba6d0 commit 0f78df1
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions airflow/airflow.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package airflow

import (
"fmt"
"os"
"path/filepath"
"regexp"
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion airflow/include/dockerfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
`)
8 changes: 3 additions & 5 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
24 changes: 21 additions & 3 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down Expand Up @@ -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")
}
}

0 comments on commit 0f78df1

Please sign in to comment.