diff --git a/.circleci/config.yml b/.circleci/config.yml index 6b7115efb1..4653e676d5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -872,57 +872,14 @@ workflows: version: 2 test-and-build: jobs: - # Fmt, vet, lint control plane and helm code - - go-fmt-and-vet-control-plane - - lint-control-plane - - go-fmt-and-vet-acceptance - - go-fmt-and-vet-helm-gen - # Unit test control plane - - test-control-plane: - requires: - - go-fmt-and-vet-control-plane - - lint-control-plane - - test-enterprise-control-plane: - filters: - branches: - # Forked pull requests have CIRCLE_BRANCH set to pull/XXX. - ignore: /pull\/[0-9]+/ - requires: - - go-fmt-and-vet-control-plane - - lint-control-plane - # Unit test CLI - - unit-cli - # Unit tests for go modules in helm and bats tests for templates - - unit-acceptance-framework: - requires: - - go-fmt-and-vet-acceptance - - unit-helm-gen: - requires: - - go-fmt-and-vet-helm-gen - - validate-helm-gen - - unit-test-helm-templates - # Build control plane binaries - - build-distro: - OS: "freebsd linux windows" - ARCH: "386" - name: build-distros-386 - requires: - - test-control-plane - - test-enterprise-control-plane + # Build this one control-plane binary so that acceptance and acceptance-tproxy will run + # The rest of these CircleCI jobs have been migrated to Github Actions. We need to wait until + # the summer of 2022 for larger puplic Github Action VMs be available before the acceptance tests can + # be moved - build-distro: OS: "darwin freebsd linux solaris windows" ARCH: "amd64" name: build-distros-amd64 - requires: - - test-control-plane - - test-enterprise-control-plane - - build-distro: - OS: "linux" - ARCH: "arm arm64" - name: build-distros-arm-arm64 - requires: - - test-control-plane - - test-enterprise-control-plane - dev-upload-docker: context: consul-ci requires: @@ -931,15 +888,9 @@ workflows: - acceptance: requires: - dev-upload-docker - - unit-test-helm-templates - - unit-acceptance-framework - - unit-cli - acceptance-tproxy: requires: - dev-upload-docker - - unit-test-helm-templates - - unit-acceptance-framework - - unit-cli nightly-acceptance-tests: triggers: - schedule: diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 0000000000..8ebb4fb3b2 --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,300 @@ +name: test-and-build +on: + push: + +env: + TEST_RESULTS: /tmp/test-results # path to where test results are saved + CONSUL_VERSION: 1.11.2 # Consul's OSS version to use in tests + CONSUL_ENT_VERSION: 1.11.2+ent # Consul's enterprise version to use in tests + GOTESTSUM_VERSION: 1.6.4 # You cannot use environment variables with workflows. The gotestsum version is hardcoded in the reusable workflows too. + +jobs: + validate-helm-gen: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup go + uses: actions/setup-go@v2 + with: + go-version: 1.17.2 + + - name: Setup go mod cache + uses: actions/cache@v2 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Validate helm gen + working-directory: hack/helm-reference-gen + run: | + go run ./... -validate + + golangci-lint-helm-gen: + uses: hashicorp/consul-k8s/.github/workflows/reusable-golangci-lint.yml@main + with: + directory: hack/helm-reference-gen + go-version: 1.17.2 + #TODO: This is a workaround in order to get pipelines working. godot and staticcheck fail for helm-reference-gen + args: "--no-config --disable-all --enable gofmt,govet" + + unit-helm-gen: + needs: [golangci-lint-helm-gen, validate-helm-gen] + uses: hashicorp/consul-k8s/.github/workflows/reusable-unit.yml@main + with: + directory: hack/helm-reference-gen + go-version: 1.17.2 + + unit-test-helm-templates: + needs: [unit-helm-gen] + runs-on: ubuntu-latest + container: + image: docker.mirror.hashicorp.services/hashicorpdev/consul-helm-test:0.10.0 + options: --user 1001 + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Run Unit Tests + working-directory: charts/consul + run: bats --jobs 4 ./test/unit + + lint-control-plane: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup go + uses: actions/setup-go@v2 + with: + go-version: 1.17.2 + + - run: go get -u github.com/hashicorp/lint-consul-retry && lint-consul-retry + + - name: Run lint + working-directory: control-plane + run: go run hack/lint-api-new-client/main.go + + golangci-lint-control-plane: + uses: hashicorp/consul-k8s/.github/workflows/reusable-golangci-lint.yml@main + with: + directory: control-plane + go-version: 1.17.2 + + test-control-plane: + needs: [lint-control-plane, golangci-lint-control-plane] + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup go + uses: actions/setup-go@v2 + with: + go-version: 1.17.2 + + - name: Setup go mod cache + uses: actions/cache@v2 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Install gotestsum + run: | + wget https://github.com/gotestyourself/gotestsum/releases/download/v${{env.GOTESTSUM_VERSION}}/gotestsum_${{env.GOTESTSUM_VERSION}}_linux_amd64.tar.gz + sudo tar -C /usr/local/bin -xzf gotestsum_${{env.GOTESTSUM_VERSION}}_linux_amd64.tar.gz + rm gotestsum_${{env.GOTESTSUM_VERSION}}_linux_amd64.tar.gz + + - run: mkdir -p ${{env.TEST_RESULTS}} + - run: echo "$HOME/bin" >> $GITHUB_PATH + + - name: Download consul + working-directory: control-plane + run: | + mkdir -p $HOME/bin + wget https://releases.hashicorp.com/consul/${{env.CONSUL_VERSION}}/consul_${{env.CONSUL_VERSION}}_linux_amd64.zip && \ + unzip consul_${{env.CONSUL_VERSION}}_linux_amd64.zip -d $HOME/bin && \ + rm consul_${{env.CONSUL_VERSION}}_linux_amd64.zip + chmod +x $HOME/bin/consul + + - name: Run go tests + working-directory: control-plane + run: | + PACKAGE_NAMES=$(go list ./...) + gotestsum --junitfile ${{env.TEST_RESULTS}}/gotestsum-report.xml -- -p 4 $PACKAGE_NAMES + + test-enterprise-control-plane: + if: github.repository_owner == 'hashicorp' # Do not run on forks as this requires secrets + needs: [lint-control-plane, golangci-lint-control-plane] + runs-on: ubuntu-latest + env: + CONSUL_LICENSE: ${{secrets.CONSUL_LICENSE}} + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup go + uses: actions/setup-go@v2 + with: + go-version: 1.17.2 + + - name: Setup go mod cache + uses: actions/cache@v2 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Install gotestsum + run: | + wget https://github.com/gotestyourself/gotestsum/releases/download/v${{env.GOTESTSUM_VERSION}}/gotestsum_${{env.GOTESTSUM_VERSION}}_linux_amd64.tar.gz + sudo tar -C /usr/local/bin -xzf gotestsum_${{env.GOTESTSUM_VERSION}}_linux_amd64.tar.gz + rm gotestsum_${{env.GOTESTSUM_VERSION}}_linux_amd64.tar.gz + + - run: mkdir -p ${{env.TEST_RESULTS}} + - run: echo "$HOME/bin" >> $GITHUB_PATH + + - name: Download consul + working-directory: control-plane + run: | + mkdir -p $HOME/bin + wget https://releases.hashicorp.com/consul/${{env.CONSUL_ENT_VERSION}}/consul_${{env.CONSUL_ENT_VERSION}}_linux_amd64.zip && \ + unzip consul_${{env.CONSUL_ENT_VERSION}}_linux_amd64.zip -d $HOME/bin && \ + rm consul_${{env.CONSUL_ENT_VERSION}}_linux_amd64.zip + chmod +x $HOME/bin/consul + + - name: Run go tests + working-directory: control-plane + run: | + PACKAGE_NAMES=$(go list ./...) + gotestsum --junitfile ${{env.TEST_RESULTS}}/gotestsum-report.xml -- -tags=enterprise -p 4 $PACKAGE_NAMES + + build-distros: + needs: [test-control-plane, test-enterprise-control-plane] + runs-on: ubuntu-latest + strategy: + matrix: + include: + - {go: "1.17.2", goos: "linux", goarch: "386"} + - {go: "1.17.2", goos: "linux", goarch: "amd64"} + - {go: "1.17.2", goos: "linux", goarch: "arm"} + - {go: "1.17.2", goos: "linux", goarch: "arm64"} + fail-fast: true + + name: Go ${{ matrix.go }} ${{ matrix.goos }} ${{ matrix.goarch }} build + steps: + - uses: actions/checkout@v2 + + - name: Setup go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go }} + + - name: Build + working-directory: control-plane + env: + GOOS: ${{ matrix.goos }} + GOARCH: ${{ matrix.goarch }} + CGO_ENABLED: 0 + run: | + XC_OS=${{ matrix.goos }} XC_ARCH=${{ matrix.goarch }} ./build-support/scripts/build-local.sh + zip -r -j consul-k8s_${{ matrix.goos }}_${{ matrix.goarch }}.zip bin + + - uses: actions/upload-artifact@v2 + with: + name: consul-k8s_${{ matrix.goos }}_${{ matrix.goarch }}.zip + path: control-plane/consul-k8s_${{ matrix.goos }}_${{ matrix.goarch }}.zip + + golangci-lint-acceptance: + uses: hashicorp/consul-k8s/.github/workflows/reusable-golangci-lint.yml@main + with: + directory: acceptance + go-version: 1.17.2 + + unit-acceptance-framework: + needs: golangci-lint-acceptance + uses: hashicorp/consul-k8s/.github/workflows/reusable-unit.yml@main + with: + directory: acceptance/framework + go-version: 1.17.2 + + golangci-lint-cli: + uses: hashicorp/consul-k8s/.github/workflows/reusable-golangci-lint.yml@main + with: + directory: cli + go-version: 1.17.2 + + unit-cli: + needs: golangci-lint-cli + uses: hashicorp/consul-k8s/.github/workflows/reusable-unit.yml@main + with: + directory: cli + go-version: 1.17.2 + +# Disabling for now until we get faster VMs to run acceptance tests. Faster VMs for Github Actions are supposed +# to be available in the summer of 2022. For now, run the dev-upload docker and acceptance tests in CircleCI +# dev-upload-docker: +# if: github.repository_owner == 'hashicorp' # Do not run on forks as this requires secrets +# needs: build-distros +# runs-on: ubuntu-latest +# +# env: +# GITHUB_PULL_REQUEST: ${{github.event.pull_request.number}} +# DOCKER_USER: ${{secrets.DOCKER_USER}} +# DOCKER_PASS: ${{secrets.DOCKER_PASS}} +# steps: +# - uses: actions/checkout@v2 +# +# - run: mkdir -p control-plane/pkg/bin/linux_amd64 +# +# - uses: actions/download-artifact@v3 +# with: +# name: consul-k8s_linux_amd64.zip +# path: control-plane +# +# - name: Docker build +# working-directory: control-plane +# run: | +# unzip consul-k8s_linux_amd64.zip -d ./pkg/bin/linux_amd64 +# make ci.dev-docker-github +# +# acceptance-tproxy: +# needs: [unit-cli, dev-upload-docker, unit-acceptance-framework, unit-test-helm-templates] +# needs: dev-upload-docker +# uses: hashicorp/consul-k8s/.github/workflows/reusable-acceptance.yml@main +# with: +# name: acceptance-tproxy +# directory: acceptance/tests +# go-version: 1.17.2 +# additional-flags: "-use-kind -kubecontext=kind-dc1 -secondary-kubecontext=kind-dc2 -enable-transparent-proxy" +# gotestsum-version: 1.6.4 +# secrets: +# CONSUL_ENT_LICENSE: ${{ secrets.CONSUL_ENT_LICENSE }} +# +# acceptance: +# #needs: [unit-cli, dev-upload-docker, unit-acceptance-framework, unit-test-helm-templates] +# needs: dev-upload-docker +# uses: hashicorp/consul-k8s/.github/workflows/reusable-acceptance.yml@main +# with: +# name: acceptance +# directory: acceptance/tests +# go-version: 1.17.2 +# additional-flags: "-use-kind -kubecontext=kind-dc1 -secondary-kubecontext=kind-dc2" +# gotestsum-version: 1.6.4 +# secrets: +# CONSUL_ENT_LICENSE: ${{ secrets.CONSUL_ENT_LICENSE }} + + diff --git a/.github/workflows/golangci-lint-acceptance.yml b/.github/workflows/golangci-lint-acceptance.yml deleted file mode 100644 index d41efb33af..0000000000 --- a/.github/workflows/golangci-lint-acceptance.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: golangci-lint-acceptance -on: - push: - tags: - - v* - branches: - - main - pull_request: -jobs: - golangci: - name: lint-acceptance - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: golangci-lint-acceptance - uses: golangci/golangci-lint-action@v2 - with: - version: v1.41.1 - # Optional: working directory, useful for monorepos - # TODO: we may need to modify this when monorepo comes, it could be helpful for when we test - # only control-plane components in a PR, or some other scenario. - # working-directory: somedir - working-directory: acceptance diff --git a/.github/workflows/golangci-lint-cli.yml b/.github/workflows/golangci-lint-cli.yml deleted file mode 100644 index 50860bbabb..0000000000 --- a/.github/workflows/golangci-lint-cli.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: golangci-lint-cli -on: - push: - tags: - - v* - branches: - - main - pull_request: -jobs: - golangci: - name: lint-cli - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: golangci-lint-cli - uses: golangci/golangci-lint-action@v2 - with: - version: v1.41.1 - # Optional: working directory, useful for monorepos - working-directory: cli diff --git a/.github/workflows/golangci-lint-control-plane.yml b/.github/workflows/golangci-lint-control-plane.yml deleted file mode 100644 index 4112818cb0..0000000000 --- a/.github/workflows/golangci-lint-control-plane.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: golangci-lint-control-plane -on: - push: - tags: - - v* - branches: - - main - pull_request: -jobs: - golangci: - name: lint-control-plane - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: golangci-lint - uses: golangci/golangci-lint-action@v2 - with: - version: v1.41.1 - # Optional: working directory, useful for monorepos - # TODO: we may need to modify this when monorepo comes, it could be helpful for when we test - # only control-plane components in a PR, or some other scenario. - # working-directory: somedir - working-directory: control-plane diff --git a/.github/workflows/reusable-acceptance.yml b/.github/workflows/reusable-acceptance.yml new file mode 100644 index 0000000000..56389bb346 --- /dev/null +++ b/.github/workflows/reusable-acceptance.yml @@ -0,0 +1,128 @@ +name: reusable-acceptance + +on: + workflow_call: + inputs: + name: + required: true + type: string + additional-flags: + required: false + type: string + default: "" + consul-k8s-image: + required: false + type: string + default: docker.mirror.hashicorp.services/hashicorpdev/consul-k8s-control-plane:latest + directory: + required: true + type: string + go-version: + required: true + type: string + gotestsum-version: + required: true + type: string + kind-version: + required: false + type: string + default: "v1.22.4" + secrets: + CONSUL_ENT_LICENSE: + required: true + +# Environment variables can only be used at the step level +env: + TEST_RESULTS: /tmp/test-results # path to where test results are saved + CONSUL_ENT_LICENSE: ${{ secrets.CONSUL_ENT_LICENSE }} + +jobs: + job: + runs-on: ubuntu-latest + strategy: + matrix: + include: # I am really sorry for this but I could not find a way to automatically split our tests into several runners. For now, split manually. + - {runner: "0", test-packages: "basic connect consul-dns"} + - {runner: "1", test-packages: "controller example ingress-gateway"} + - {runner: "2", test-packages: "mesh-gateway metrics"} + - {runner: "3", test-packages: "partitions sync terminating-gateway"} + - {runner: "4", test-packages: "vault"} + + fail-fast: true + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup go + uses: actions/setup-go@v2 + with: + go-version: ${{ inputs.go-version }} + + - name: Setup go mod cache + uses: actions/cache@v2 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Install gotestsum + run: | + wget https://github.com/gotestyourself/gotestsum/releases/download/v"${{ inputs.gotestsum-version }}"/gotestsum_"${{ inputs.gotestsum-version }}"_linux_amd64.tar.gz + sudo tar -C /usr/local/bin -xzf gotestsum_"${{ inputs.gotestsum-version }}"_linux_amd64.tar.gz + rm gotestsum_"${{ inputs.gotestsum-version }}"_linux_amd64.tar.gz + + - run: mkdir -p ${{ env.TEST_RESULTS }} + + - name: go mod download + working-directory: ${{ inputs.directory }} + run: go mod download + + - name: Create kind clusters + run: | + kind create cluster --name dc1 --image kindest/node:${{ inputs.kind-version }} + kind create cluster --name dc2 --image kindest/node:${{ inputs.kind-version }} + + # We have to run the tests for each package separately so that we can + # exit early if any test fails (-failfast only works within a single + # package). + - name: Run acceptance tests ${{ matrix.runner }} + working-directory: ${{ inputs.directory }} + if: github.repository_owner == 'hashicorp' # This prevents running on forks + run: | + exit_code=0 + echo "Running packages: ${{ matrix.test-packages }}" + for pkg in $(echo ${{ matrix.test-packages }}) + do + fullpkg="github.com/hashicorp/consul-k8s/${{ inputs.directory }}/${pkg}" + echo "Testing package: ${fullpkg}" + if ! gotestsum --jsonfile=jsonfile-${pkg////-} -- ${fullpkg} -p 1 -timeout 2h -failfast \ + ${{ inputs.additional-flags }} \ + -enable-enterprise \ + -enable-multi-cluster \ + -debug-directory=${{ env.TEST_RESULTS }}/debug \ + -consul-k8s-image=${{ inputs.consul-k8s-image }} + then + echo "Tests in ${pkg} failed, aborting early" + exit_code=1 + break + fi + done + gotestsum --raw-command --junitfile "${{ env.TEST_RESULTS }}/gotestsum-report.xml" -- cat jsonfile* + exit $exit_code + + - name: Upload tests + if: always() + uses: actions/upload-artifact@v2 + with: + name: ${{ inputs.name }}-${{ matrix.test-packages }}-gotestsum-report.xml + path: ${{ env.TEST_RESULTS }}/gotestsum-report.xml + + - name: Upload debug (on failure) + if: failure() + uses: actions/upload-artifact@v2 + with: + name: ${{ inputs.name }}-${{ matrix.test-packages }}-debug-info + path: ${{ env.TEST_RESULTS }}/debug diff --git a/.github/workflows/reusable-golangci-lint.yml b/.github/workflows/reusable-golangci-lint.yml new file mode 100644 index 0000000000..5475e7ae75 --- /dev/null +++ b/.github/workflows/reusable-golangci-lint.yml @@ -0,0 +1,29 @@ +name: golangci-lint + +on: + workflow_call: + inputs: + directory: + required: true + type: string + go-version: + required: true + type: string + args: + required: false + type: string + +jobs: + job: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: golangci-lint-${{inputs.directory}} + uses: golangci/golangci-lint-action@v2 + with: + version: v1.41.1 + working-directory: ${{inputs.directory}} + args: ${{inputs.args}} diff --git a/.github/workflows/reusable-unit.yml b/.github/workflows/reusable-unit.yml new file mode 100644 index 0000000000..1183e1922c --- /dev/null +++ b/.github/workflows/reusable-unit.yml @@ -0,0 +1,57 @@ +name: reusable-unit + +on: + workflow_call: + inputs: + directory: + required: true + type: string + go-version: + required: true + type: string + +# Environment variables can only be used at the step level +env: + TEST_RESULTS: /tmp/test-results # path to where test results are saved + GOTESTSUM_VERSION: 1.6.4 + +jobs: + job: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup go + uses: actions/setup-go@v2 + with: + go-version: ${{inputs.go-version}} + + - name: Setup go mod cache + uses: actions/cache@v2 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Install gotestsum + run: | + wget https://github.com/gotestyourself/gotestsum/releases/download/v${{env.GOTESTSUM_VERSION}}/gotestsum_${{env.GOTESTSUM_VERSION}}_linux_amd64.tar.gz + sudo tar -C /usr/local/bin -xzf gotestsum_${{env.GOTESTSUM_VERSION}}_linux_amd64.tar.gz + rm gotestsum_${{env.GOTESTSUM_VERSION}}_linux_amd64.tar.gz + + - run: mkdir -p ${{env.TEST_RESULTS}} + + - name: go mod download + working-directory: ${{inputs.directory}} + run: go mod download + + - name: Run tests + working-directory: ${{inputs.directory}} + run: | + gotestsum --junitfile ${{env.TEST_RESULTS}}/gotestsum-report.xml ./... -- -p 4 + diff --git a/.golangci.yml b/.golangci.yml index 99e8b2ee8c..f96c523906 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -3,6 +3,7 @@ linters: enable: - gofmt - godot + - govet # TODO: re-enable things as we have main cleaned up vs the defaults #- stylecheck #- goconst diff --git a/control-plane/Makefile b/control-plane/Makefile index d882018031..eb174b3c1c 100644 --- a/control-plane/Makefile +++ b/control-plane/Makefile @@ -27,6 +27,7 @@ CONSUL_K8S_IMAGE_VERSION?=latest ci.dev-tree: @$(SHELL) $(CURDIR)/build-support/scripts/dev.sh $(DEV_PUSH_ARG) +# TODO: Remove this ci.dev-docker target once we move the acceptance tests to Github Actions. # In CircleCI, the linux binary will be attached from a previous step at pkg/bin/linux_amd64/. This make target # should only run in CI and not locally. ci.dev-docker: @@ -47,4 +48,24 @@ ifeq ($(CIRCLE_BRANCH), main) @docker push $(CI_DEV_DOCKER_NAMESPACE)/$(CI_DEV_DOCKER_IMAGE_NAME):latest endif -.PHONY: ci.dev-tree ci.dev-docker +# In Github Actions, the linux binary will be attached from a previous step at pkg/bin/linux_amd64/. This make target +# should only run in CI and not locally. +ci.dev-docker-github: + @echo "Pulling consul-k8s container image - $(CONSUL_K8S_IMAGE_VERSION)" + @docker pull hashicorp/consul-k8s:$(CONSUL_K8S_IMAGE_VERSION) >/dev/null #todo change this back after pulling it the first time since the dockerfile is FROM this image + @echo "Building consul-k8s Development container - $(CI_DEV_DOCKER_IMAGE_NAME)" + @docker build -t '$(CI_DEV_DOCKER_NAMESPACE)/$(CI_DEV_DOCKER_IMAGE_NAME):$(GIT_COMMIT)' \ + --build-arg CONSUL_K8S_IMAGE_VERSION=$(CONSUL_K8S_IMAGE_VERSION) \ + --label COMMIT_SHA=$(GITHUB_SHA) \ + --label PULL_REQUEST=$(GITHIB_PULL_REQUEST) \ + --label GITHUB_BUILD_URL=$(GITHUB_SERVER_URL)/$(GITHUB_REPOSITORY)/actions/runs/$(GITHUB_RUN_ID) \ + $(CI_DEV_DOCKER_WORKDIR) -f $(CURDIR)/build-support/docker/Dev.dockerfile + @echo $(DOCKER_PASS) | docker login -u="$(DOCKER_USER)" --password-stdin + @echo "Pushing dev image to: https://cloud.docker.com/u/$(CI_DEV_DOCKER_NAMESPACE)/repository/docker/$(CI_DEV_DOCKER_NAMESPACE)/$(CI_DEV_DOCKER_IMAGE_NAME)" + @docker push $(CI_DEV_DOCKER_NAMESPACE)/$(CI_DEV_DOCKER_IMAGE_NAME):$(GIT_COMMIT) +ifeq ($(GITHUB_REF_NAME), main) + @docker tag $(CI_DEV_DOCKER_NAMESPACE)/$(CI_DEV_DOCKER_IMAGE_NAME):$(GIT_COMMIT) $(CI_DEV_DOCKER_NAMESPACE)/$(CI_DEV_DOCKER_IMAGE_NAME):latest + @docker push $(CI_DEV_DOCKER_NAMESPACE)/$(CI_DEV_DOCKER_IMAGE_NAME):latest +endif + +.PHONY: ci.dev-tree ci.dev-docker ci.dev-docker-github