Skip to content

Commit

Permalink
Updates Vendor Dependencies (#1762)
Browse files Browse the repository at this point in the history
  • Loading branch information
schnie authored Dec 17, 2024
1 parent 9c82678 commit 986bdcc
Show file tree
Hide file tree
Showing 32 changed files with 4,157 additions and 2,133 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ jobs:
working_directory: /go/src/github.com/astronomer/astro-cli
docker:
- image: quay.io/astronomer/ap-dind-golang:24.0.6
resource_class: large
steps:
- lint
test:
Expand Down
5 changes: 4 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ linters-settings:
funlen:
lines: 100
statements: 50
gci:
sections:
- prefix(github.com/golangci/golangci-lint)
goconst:
min-len: 3
min-occurrences: 3
Expand Down Expand Up @@ -72,12 +75,12 @@ linters:
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- bodyclose
# to be added once migrated out of logrus logger
# - depguard
- dogsled
- dupl
- errcheck
- copyloopvar
- exhaustive
- goconst
- gocritic
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ generate:

lint:
go run github.com/golangci/golangci-lint/cmd/golangci-lint version
go run github.com/golangci/golangci-lint/cmd/golangci-lint run --timeout 15m0s
go run github.com/golangci/golangci-lint/cmd/golangci-lint run --timeout 15m0s --verbose

build:
go build -o ${OUTPUT} -ldflags "${LDFLAGS_VERSION}" main.go
Expand Down
38 changes: 37 additions & 1 deletion airflow-client/mocks/Client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 49 additions & 26 deletions airflow/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ import (
"text/tabwriter"
"time"

"github.com/Masterminds/semver/v3"
"github.com/astronomer/astro-cli/airflow/runtimes"
"github.com/astronomer/astro-cli/pkg/logger"

semver "github.com/Masterminds/semver/v3"
airflowTypes "github.com/astronomer/astro-cli/airflow/types"
astrocore "github.com/astronomer/astro-cli/astro-client-core"
astroplatformcore "github.com/astronomer/astro-cli/astro-client-platform-core"
Expand All @@ -24,21 +22,22 @@ import (
"github.com/astronomer/astro-cli/docker"
"github.com/astronomer/astro-cli/pkg/ansi"
"github.com/astronomer/astro-cli/pkg/fileutil"
"github.com/astronomer/astro-cli/pkg/logger"
"github.com/astronomer/astro-cli/pkg/util"
"github.com/astronomer/astro-cli/settings"
composeInterp "github.com/compose-spec/compose-go/interpolation"
"github.com/compose-spec/compose-go/loader"
"github.com/compose-spec/compose-go/types"
"github.com/compose-spec/compose-go/v2/interpolation"
"github.com/compose-spec/compose-go/v2/loader"
composetypes "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/cli/flags"
"github.com/docker/compose/v2/cmd/formatter"
"github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/compose"
docker_types "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/versions"
"github.com/pkg/browser"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

const (
Expand Down Expand Up @@ -177,7 +176,7 @@ func DockerComposeInit(airflowHome, envFile, dockerfile, imageName string) (*Doc
logger.Fatalf("error init compose client %s", err)
}

composeService := compose.NewComposeService(dockerCli.Client(), &configfile.ConfigFile{})
composeService := compose.NewComposeService(dockerCli)

return &DockerCompose{
airflowHome: airflowHome,
Expand Down Expand Up @@ -253,6 +252,9 @@ func (d *DockerCompose) Start(imageName, settingsFile, composeFile, buildSecretS
// Start up our project
err = d.composeService.Up(context.Background(), project, api.UpOptions{
Create: api.CreateOptions{},
Start: api.StartOptions{
Project: project,
},
})
if err != nil {
return errors.Wrap(err, composeRecreateErrMsg)
Expand Down Expand Up @@ -331,7 +333,7 @@ func (d *DockerCompose) Stop(waitForExit bool) error {
}

// Pause our project
err = d.composeService.Stop(context.Background(), project, api.StopOptions{})
err = d.composeService.Stop(context.Background(), project.Name, api.StopOptions{})
if err != nil {
return errors.Wrap(err, composePauseErrMsg)
}
Expand Down Expand Up @@ -401,6 +403,13 @@ func (d *DockerCompose) PS() error {

// Kill stops a local airflow development cluster
func (d *DockerCompose) Kill() error {
// Killing an already killed project produces an unsightly warning,
// so we briefly switch to a higher level before running the kill command.
// We then swap back to the original level.
originalLevel := logrus.GetLevel()
logrus.SetLevel(logrus.ErrorLevel)
defer logrus.SetLevel(originalLevel)

// Shut down our project
err := d.composeService.Down(context.Background(), d.projectName, api.DownOptions{Volumes: true, RemoveOrphans: true})
if err != nil {
Expand All @@ -422,7 +431,7 @@ func (d *DockerCompose) Logs(follow bool, containerNames ...string) error {
return errors.New("cannot view logs, project not running")
}

consumer := formatter.NewLogConsumer(context.Background(), os.Stdout, true, false)
consumer := formatter.NewLogConsumer(context.Background(), os.Stdout, os.Stderr, true, false, true)

err = d.composeService.Logs(context.Background(), d.projectName, consumer, api.LogOptions{
Services: containerNames,
Expand All @@ -438,7 +447,7 @@ func (d *DockerCompose) Logs(follow bool, containerNames ...string) error {
// Run creates using docker exec
// inspired from https://github.com/docker/cli/tree/master/cli/command/container
func (d *DockerCompose) Run(args []string, user string) error {
execConfig := &docker_types.ExecConfig{
execConfig := &container.ExecOptions{
AttachStdout: true,
Cmd: args,
}
Expand All @@ -463,7 +472,7 @@ func (d *DockerCompose) Run(args []string, user string) error {
return errors.New("exec ID is empty")
}

execStartCheck := docker_types.ExecStartCheck{
execStartCheck := container.ExecStartOptions{
Detach: execConfig.Detach,
}

Expand Down Expand Up @@ -1063,10 +1072,10 @@ func (d *DockerCompose) Parse(customImageName, deployImageName, buildSecretStrin
return err
}

func (d *DockerCompose) Bash(container string) error {
func (d *DockerCompose) Bash(component string) error {
// exec into schedueler by default
if container == "" {
container = SchedulerDockerContainerName
if component == "" {
component = SchedulerDockerContainerName
}

// query for container names
Expand All @@ -1082,7 +1091,7 @@ func (d *DockerCompose) Bash(container string) error {
// find container name of specified container
var containerName string
for i := range psInfo {
if strings.Contains(psInfo[i].Name, container) {
if strings.Contains(psInfo[i].Name, component) {
containerName = psInfo[i].Name
}
}
Expand Down Expand Up @@ -1278,7 +1287,7 @@ func (d *DockerCompose) checkAiflowVersion() (uint64, error) {
}

// createProject creates project with yaml config as context
var createDockerProject = func(projectName, airflowHome, envFile, buildImage, settingsFile, composeFile string, imageLabels map[string]string) (*types.Project, error) {
var createDockerProject = func(projectName, airflowHome, envFile, buildImage, settingsFile, composeFile string, imageLabels map[string]string) (*composetypes.Project, error) {
// Generate the docker-compose yaml
var yaml string
var err error
Expand All @@ -1294,9 +1303,9 @@ var createDockerProject = func(projectName, airflowHome, envFile, buildImage, se
}
}

var configs []types.ConfigFile
var configs []composetypes.ConfigFile

configs = append(configs, types.ConfigFile{
configs = append(configs, composetypes.ConfigFile{
Filename: "compose.yaml",
Content: []byte(yaml),
})
Expand All @@ -1306,7 +1315,7 @@ var createDockerProject = func(projectName, airflowHome, envFile, buildImage, se
return nil, errors.Wrapf(err, "Failed to open the compose file: %s", composeOverrideFilename)
}
if err == nil {
configs = append(configs, types.ConfigFile{
configs = append(configs, composetypes.ConfigFile{
Filename: "docker-compose.override.yml",
Content: composeBytes,
})
Expand All @@ -1315,23 +1324,37 @@ var createDockerProject = func(projectName, airflowHome, envFile, buildImage, se
var loadOptions []func(*loader.Options)

nameLoadOpt := func(opts *loader.Options) {
opts.Name = projectName
opts.Name = normalizeName(opts.Name)
opts.Interpolate = &composeInterp.Options{
opts.SetProjectName(normalizeName(projectName), true)
opts.Interpolate = &interpolation.Options{
LookupValue: os.LookupEnv,
}
}

loadOptions = append(loadOptions, nameLoadOpt)

project, err := loader.Load(types.ConfigDetails{
project, err := loader.LoadWithContext(context.Background(), composetypes.ConfigDetails{
ConfigFiles: configs,
WorkingDir: airflowHome,
}, loadOptions...)

// The latest versions of compose libs handle adding these labels at an outer layer,
// near the cobra entrypoint. Without these labels, compose will lose track of the containers its
// starting for a given project and downstream library calls will fail.
for name, s := range project.Services {
s.CustomLabels = map[string]string{
api.ProjectLabel: project.Name,
api.ServiceLabel: name,
api.VersionLabel: api.ComposeVersion,
api.WorkingDirLabel: project.WorkingDir,
api.ConfigFilesLabel: strings.Join(project.ComposeFiles, ","),
api.OneoffLabel: "False",
}
project.Services[name] = s
}
return project, err
}

func printStatus(settingsFile string, envConns map[string]astrocore.EnvironmentObjectConnection, project *types.Project, composeService api.Service, airflowDockerVersion uint64, noBrowser bool) error {
func printStatus(settingsFile string, envConns map[string]astrocore.EnvironmentObjectConnection, project *composetypes.Project, composeService api.Service, airflowDockerVersion uint64, noBrowser bool) error {
psInfo, err := composeService.Ps(context.Background(), project.Name, api.PsOptions{
All: true,
})
Expand Down
Loading

0 comments on commit 986bdcc

Please sign in to comment.