Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/go_modules/github.com/container…
Browse files Browse the repository at this point in the history
…d/containerd-1.6.18
  • Loading branch information
marciogoda authored Dec 6, 2023
2 parents f159554 + c78c3db commit 24d40da
Show file tree
Hide file tree
Showing 19 changed files with 437 additions and 119 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-and-upload-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ name: Build and upload docs
jobs:
this:
name: Build and publish release
runs-on: ubuntu-latest
runs-on: 'ubuntu-latest'
env:
FASTLY_API_KEY: ${{ secrets.FASTLY_API_KEY }}
AWS_ACCESS_KEY_ID: ${{ secrets.CAPPLATFORM_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.CAPPLATFORM_AWS_SECRET_ACCESS_KEY }}
SESSION_NAME: gh-action/${{ github.workflow }}
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Build docs
run: scripts/build-docs.sh
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ name: Build and publish release
jobs:
build:
name: Build and publish release
runs-on: ubuntu-latest
runs-on: 'ubuntu-latest'
steps:
- name: Checkout code
uses: actions/checkout@master
- uses: actions/setup-go@v1
- uses: actions/setup-go@v2
with:
go-version: '1.19'
go-version: '1.20.5'
- uses: actions/cache@v1
with:
path: ~/go/pkg/mod
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.19'
go-version: '1.20.5'
- uses: actions/cache@v1
with:
path: ~/go/pkg/mod
Expand Down
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# Changelog

## [v0.59.0](https://github.com/mergermarket/cdflow2/releases/tag/v0.59.0) - 2023-05-24

### Added

- Add an option for Terraform involved commands (release, deploy, destroy, setup) to set `TF_LOG` level.

## [v0.58.0](https://github.com/mergermarket/cdflow2/releases/tag/v0.58.0) - 2023-03-22

### Fixed

- Fix volume in use error during release command ([#43](https://github.com/mergermarket/cdflow2/pull/43))

## [v0.57.0](https://github.com/mergermarket/cdflow2/releases/tag/v0.57.0) - 2023-02-17

### Fixed

- Fix terraform providers upload during release command ([#33](https://github.com/mergermarket/cdflow2/pull/33))

> WARNING!
> Using terraform 0.13.x image version is not recommended anymore for cdflow2.
> Please upgrade to 0.14 or newer otherwise you will see increased build times when running 'release' command.
## [v0.56.0](https://github.com/mergermarket/cdflow2/releases/tag/v0.56.0) - 2023-01-25

### Fixed
Expand Down
51 changes: 42 additions & 9 deletions deploy/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package deploy
import (
"errors"
"fmt"
"io"
"os"
"strings"

Expand All @@ -14,10 +15,12 @@ import (

// CommandArgs contains specific arguments to the deploy command.
type CommandArgs struct {
EnvName string
Version string
PlanOnly bool
StateShouldExist *bool
EnvName string
Version string
PlanOnly bool
TerraformLogLevel string
StateShouldExist *bool
ErrorOnResourceDestroy bool
}

// ParseArgs parses command line arguments to the deploy subcommand.
Expand All @@ -27,8 +30,16 @@ func ParseArgs(args []string) (*CommandArgs, error) {
result.StateShouldExist = &T // set default to true

i := 0
take := func() (string, error) {
i++
if i >= len(args) {
return "", errors.New("missing value")
}

return args[i], nil
}
for ; i < len(args); i++ {
_, err := handleArgs(args[i], &result)
_, err := handleArgs(args[i], &result, take)
if err != nil {
return nil, err
}
Expand All @@ -45,9 +56,9 @@ func ParseArgs(args []string) (*CommandArgs, error) {
return &result, nil
}

func handleArgs(arg string, commandArgs *CommandArgs) (bool, error) {
func handleArgs(arg string, commandArgs *CommandArgs, take func() (string, error)) (bool, error) {
if strings.HasPrefix(arg, "-") {
return handleFlag(arg, commandArgs)
return handleFlag(arg, commandArgs, take)
} else if commandArgs.EnvName == "" {
commandArgs.EnvName = arg
} else if commandArgs.Version == "" {
Expand All @@ -58,19 +69,32 @@ func handleArgs(arg string, commandArgs *CommandArgs) (bool, error) {
return false, nil
}

func handleFlag(arg string, commandArgs *CommandArgs) (bool, error) {
func handleFlag(arg string, commandArgs *CommandArgs, take func() (string, error)) (bool, error) {
var F = false

if arg == "-p" || arg == "--plan-only" {
commandArgs.PlanOnly = true
} else if arg == "-n" || arg == "--new-state" {
commandArgs.StateShouldExist = &F
} else if arg == "-e" || arg == "--error-on-destroy" {
commandArgs.ErrorOnResourceDestroy = true
} else if arg == "-t" || arg == "--terraform-log-level" {
value, err := take()
if err != nil {
return false, err
}

commandArgs.TerraformLogLevel = value
} else {
return false, errors.New("unknown deploy option: " + arg)
}
return false, nil
}

func hasResourceDelete(plan string) bool {
return !strings.Contains(plan, "0 to destroy")
}

// RunCommand runs the release command.
func RunCommand(state *command.GlobalState, args *CommandArgs, env map[string]string) (returnedError error) {
prepareTerraformResponse, buildVolume, terraformImage, err := config.SetupTerraform(state, args.StateShouldExist, args.EnvName, args.Version, env)
Expand All @@ -93,6 +117,7 @@ func RunCommand(state *command.GlobalState, args *CommandArgs, env map[string]st
terraformImage,
state.CodeDir,
buildVolume,
args.TerraformLogLevel,
)
if err != nil {
return err
Expand Down Expand Up @@ -148,14 +173,22 @@ func RunCommand(state *command.GlobalState, args *CommandArgs, env map[string]st
util.FormatInfo("creating plan"),
util.FormatCommand(strings.Join(planCommand, " ")),
)
var planBuff strings.Builder
multiWriter := io.MultiWriter(state.OutputStream, &planBuff)

if err := terraformContainer.RunCommand(
planCommand, prepareTerraformResponse.Env,
state.OutputStream, state.ErrorStream,
multiWriter, state.ErrorStream,
); err != nil {
return err
}

if args.ErrorOnResourceDestroy {
if hasResourceDelete(planBuff.String()) {
return errors.New("the plan contains resources to be deleted")
}
}

if args.PlanOnly {
return nil
}
Expand Down
33 changes: 25 additions & 8 deletions destroy/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import (

// CommandArgs contains specific arguments to the deploy command.
type CommandArgs struct {
EnvName string
Version string
PlanOnly bool
StateShouldExist *bool
EnvName string
Version string
PlanOnly bool
TerraformLogLevel string
StateShouldExist *bool
}

// ParseArgs parses command line arguments to the deploy subcommand.
Expand All @@ -27,8 +28,16 @@ func ParseArgs(args []string) (*CommandArgs, error) {
result.StateShouldExist = &T // set default to true

i := 0
take := func() (string, error) {
i++
if i >= len(args) {
return "", errors.New("missing value")
}

return args[i], nil
}
for ; i < len(args); i++ {
_, err := handleArgs(args[i], &result)
_, err := handleArgs(args[i], &result, take)
if err != nil {
return nil, err
}
Expand All @@ -45,9 +54,9 @@ func ParseArgs(args []string) (*CommandArgs, error) {
return &result, nil
}

func handleArgs(arg string, commandArgs *CommandArgs) (bool, error) {
func handleArgs(arg string, commandArgs *CommandArgs, take func() (string, error)) (bool, error) {
if strings.HasPrefix(arg, "-") {
return handleFlag(arg, commandArgs)
return handleFlag(arg, commandArgs, take)
} else if commandArgs.EnvName == "" {
commandArgs.EnvName = arg
} else if commandArgs.Version == "" {
Expand All @@ -58,9 +67,16 @@ func handleArgs(arg string, commandArgs *CommandArgs) (bool, error) {
return false, nil
}

func handleFlag(arg string, commandArgs *CommandArgs) (bool, error) {
func handleFlag(arg string, commandArgs *CommandArgs, take func() (string, error)) (bool, error) {
if arg == "-p" || arg == "--plan-only" {
commandArgs.PlanOnly = true
} else if arg == "-t" || arg == "--terraform-log-level" {
value, err := take()
if err != nil {
return false, err
}

commandArgs.TerraformLogLevel = value
} else {
return false, errors.New("unknown destroy option: " + arg)
}
Expand Down Expand Up @@ -89,6 +105,7 @@ func RunCommand(state *command.GlobalState, args *CommandArgs, env map[string]st
terraformImage,
state.CodeDir,
buildVolume,
args.TerraformLogLevel,
)
if err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions docs/src/commands/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ See [usage](./usage) for global options.
`--new-state` | `-n`
: Allow run without a pre-existing tfstate file.

`--error-on-destroy` | `-e`
: Error if any resources are marked to be destroyed during plan.

`--terraform-log-level` | `-t`
: Set Terraform log level (TF_LOG), useful for debugging.

## Description

Terraform is configured as described in [common terraform setup](common-terraform-setup), followed by commands
Expand Down
3 changes: 3 additions & 0 deletions docs/src/commands/destroy.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ See [usage](./usage) for global options.
`--plan-only` | `-p`
: Generate an execution plan only, don't destroy.

`--terraform-log-level` | `-t`
: Set Terraform log level (TF_LOG), useful for debugging.

## Description

Terraform is configured as described in [common terraform setup](common-terraform-setup), followed by commands
Expand Down
5 changes: 5 additions & 0 deletions docs/src/commands/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ See [usage](./usage) for global options.
`VERSION`
: The version being released. We recommend using evergreen version numbers (i.e. simple incrementing integers, probably from your CI service), combined with something to identify the commit - e.g. "34-a5dbc4a7".

### Options:

`--terraform-log-level` | `-t`
: Set Terraform log level (TF_LOG), useful for debugging.

## Description

Release builds each of the `builds` configured in [`cdflow.yaml`](../cdflow-yaml-reference#builds-optional),
Expand Down
3 changes: 3 additions & 0 deletions docs/src/commands/shell.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ See [usage](./usage) for global options.
`--version` | `-v`
: The released version to use to setup terraform (currently an option, but may not work without - may be made a required parameter).

`--terraform-log-level` | `-t`
: Set Terraform log level (TF_LOG), useful for debugging.

## Description

Terraform is configured as described in [common terraform setup](common-terraform-setup), followed by creating a shell.
Expand Down
29 changes: 17 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ Usage:
Args:
VERSION - the version being released. We recommend using evergreen version numbers (i.e. simple incrementing integers,
probably from your CI service), combined with something to identify the commit - e.g. "34-a5dbc4a7".
VERSION - the version being released. We recommend using evergreen version numbers (i.e. simple incrementing integers,
probably from your CI service), combined with something to identify the commit - e.g. "34-a5dbc4a7".
Options:
--release-data | -r - add key/value to release metadata (i.e. --release-data foo=bar).
--release-data | -r - add key/value to release metadata (i.e. --release-data foo=bar).
--terraform-log-level | -t - set Terraform log level (TF_LOG), useful for debugging.
` + globalOptions

Expand All @@ -66,13 +67,15 @@ Usage:
Args:
ENV - the environment being deployed to.
VERSION - the version being deployed (must match what was released).
ENV - the environment being deployed to.
VERSION - the version being deployed (must match what was released).
Options:
--plan-only | -p - create the terraform plan only, don't apply.
--new-state | -n - allow run without a pre-existing tfstate file.
--plan-only | -p - create the terraform plan only, don't apply.
--new-state | -n - allow run without a pre-existing tfstate file.
--error-on-destroy | -e - fail if a plan return any resources to destroy.
--terraform-log-level | -t - set Terraform log level (TF_LOG), useful for debugging.
` + globalOptions

Expand All @@ -90,11 +93,12 @@ Usage:
Args:
ENV - the environment containing the deployment.
ENV - the environment containing the deployment.
Options:
-v, --version - followed by the name of which version to interract with (must match a pre-existing release).
--version | -v - followed by the name of which version to interract with (must match a pre-existing release).
--terraform-log-level | -t - set Terraform log level (TF_LOG), useful for debugging.
Shell Arguments:
Expand All @@ -110,12 +114,13 @@ Usage:
Args:
ENV - the environment containing the infrastructure being destroyed.
VERSION - the version to destroy (must match a pre-existing release).
ENV - the environment containing the infrastructure being destroyed.
VERSION - the version to destroy (must match a pre-existing release).
Options:
--plan-only | -p - generate an execution plan only, don't destroy.
--plan-only | -p - generate an execution plan only, don't destroy.
--terraform-log-level | -t - set Terraform log level (TF_LOG), useful for debugging.
` + globalOptions

Expand Down
Loading

0 comments on commit 24d40da

Please sign in to comment.