From 6d4b805b51c5bed2f30bf2b1da224315435abdc7 Mon Sep 17 00:00:00 2001 From: nitrocode <7775707+nitrocode@users.noreply.github.com> Date: Wed, 25 Jan 2023 18:35:47 -0600 Subject: [PATCH 01/11] Set version based on github release tag --- .goreleaser.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.goreleaser.yml b/.goreleaser.yml index 0082426356..6c46de71ed 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -17,6 +17,7 @@ archives: format: zip files: - none* + rlcp: true checksum: name_template: 'checksums.txt' From f4fdb19db4b2d7436b8f361826fb5653df817c9f Mon Sep 17 00:00:00 2001 From: nitrocode <7775707+nitrocode@users.noreply.github.com> Date: Wed, 25 Jan 2023 18:55:04 -0600 Subject: [PATCH 02/11] Use logger --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index fec2347232..62d54fac7f 100644 --- a/main.go +++ b/main.go @@ -33,12 +33,12 @@ var ( ) func main() { - fmt.Printf("atlantis %s, commit %s, built at %s", version, commit, date) v := viper.New() logger, err := logging.NewStructuredLogger() + logger.Debug("atlantis %s, commit %s, built at %s\n", version, commit, date) if err != nil { panic(fmt.Sprintf("unable to initialize logger. %s", err.Error())) } From 637dcc807c5b7fa122659b28970ff94ba75719f6 Mon Sep 17 00:00:00 2001 From: nitrocode <7775707+nitrocode@users.noreply.github.com> Date: Wed, 25 Jan 2023 20:01:30 -0600 Subject: [PATCH 03/11] fix(docker): Set version based on github release tag --- .github/workflows/atlantis-image.yml | 26 +++++++++++++++++--------- .goreleaser.yml | 10 ++++++---- Dockerfile | 24 ++++++++++++++++-------- 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/.github/workflows/atlantis-image.yml b/.github/workflows/atlantis-image.yml index 4a93d89f20..b54f3cf29a 100644 --- a/.github/workflows/atlantis-image.yml +++ b/.github/workflows/atlantis-image.yml @@ -58,11 +58,12 @@ jobs: tags: | type=ref,event=branch type=ref,event=pr - type=semver,pattern={{version}} + type=semver,pattern={{version}},value=dev type=semver,pattern={{major}}.{{minor}} - name: Login to Packages Container registry uses: docker/login-action@v2 + if: false with: registry: ghcr.io username: ${{ github.actor }} @@ -70,13 +71,18 @@ jobs: # Publish dev image to container registry - name: Build and push atlantis:dev${{ env.IMAGE_SUFFIX }} image - if: ${{ contains(fromJson('["push", "pull_request"]'), github.event_name) }} + if: false + # if: ${{ contains(fromJson('["push", "pull_request"]'), github.event_name) }} uses: docker/build-push-action@v3 with: cache-from: type=gha cache-to: type=gha,mode=max context: . - build-args: ATLANTIS_BASE_TAG_TYPE=${{ matrix.image_type }} + build-args: | + ATLANTIS_BASE_TAG_TYPE=${{ matrix.image_type }} + ATLANTIS_VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} + ATLANTIS_COMMIT=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }} + ATLANTIS_DATE=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }} platforms: linux/arm64/v8,linux/amd64,linux/arm/v7 push: ${{ github.event_name != 'pull_request' }} tags: | @@ -86,15 +92,17 @@ jobs: # Publish release to container registry - name: Populate release version - if: | - contains(fromJson('["push", "pull_request"]'), github.event_name) && - startsWith(github.ref, 'refs/tags/') + if: false + # if: | + # contains(fromJson('["push", "pull_request"]'), github.event_name) && + # startsWith(github.ref, 'refs/tags/') run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV - name: "Build and push atlantis:${{ env.RELEASE_VERSION }} image for ${{ env.RELEASE_TYPE }} release" - if: | - contains(fromJson('["push", "pull_request"]'), github.event_name) && - startsWith(github.ref, 'refs/tags/') + if: false + # if: | + # contains(fromJson('["push", "pull_request"]'), github.event_name) && + # startsWith(github.ref, 'refs/tags/') uses: docker/build-push-action@v3 with: cache-from: type=gha diff --git a/.goreleaser.yml b/.goreleaser.yml index 6c46de71ed..7875ea4248 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -48,10 +48,12 @@ release: # Default is false. prerelease: auto -signs: - # https://goreleaser.com/customization/sign/ - - - artifacts: all +# TODO: This requires a gpg_private_key +# https://github.com/marketplace/actions/goreleaser-action#signing +# signs: +# # https://goreleaser.com/customization/sign/ +# - +# artifacts: all snapshot: name_template: "{{ incpatch .Version }}-next" diff --git a/Dockerfile b/Dockerfile index 60bdac7c76..5129dd9a3e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,11 +6,19 @@ ARG ATLANTIS_BASE_TAG_TYPE=alpine FROM golang:1.19.5-alpine AS builder +ARG ATLANTIS_VERSION=dev +ENV ATLANTIS_VERSION=${ATLANTIS_VERSION} +ARG ATLANTIS_COMMIT=none +ENV ATLANTIS_COMMIT=${ATLANTIS_COMMIT} +ARG ATLANTIS_DATE=unknown +ENV ATLANTIS_DATE=${ATLANTIS_DATE} + WORKDIR /app COPY . /app + RUN --mount=type=cache,target=/go/pkg/mod \ --mount=type=cache,target=/root/.cache/go-build \ - CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" -v -o atlantis . + CGO_ENABLED=0 go build -trimpath -ldflags "-s -w -X 'main.version=${ATLANTIS_VERSION}' -X 'main.commit=${ATLANTIS_COMMIT}' -X 'main.date=${ATLANTIS_DATE}'" -v -o atlantis . # Stage 2 # The runatlantis/atlantis-base is created by docker-base/Dockerfile @@ -48,20 +56,20 @@ RUN AVAILABLE_TERRAFORM_VERSIONS="1.0.11 1.1.9 1.2.9 ${DEFAULT_TERRAFORM_VERSION ENV DEFAULT_CONFTEST_VERSION=0.38.0 RUN AVAILABLE_CONFTEST_VERSIONS="${DEFAULT_CONFTEST_VERSION}" && \ - case ${TARGETPLATFORM} in \ + case "${TARGETPLATFORM}" in \ "linux/amd64") CONFTEST_ARCH=x86_64 ;; \ "linux/arm64") CONFTEST_ARCH=arm64 ;; \ # There is currently no compiled version of conftest for armv7 "linux/arm/v7") CONFTEST_ARCH=x86_64 ;; \ esac && \ for VERSION in ${AVAILABLE_CONFTEST_VERSIONS}; do \ - curl -LOs https://github.com/open-policy-agent/conftest/releases/download/v${VERSION}/conftest_${VERSION}_Linux_${CONFTEST_ARCH}.tar.gz && \ - curl -LOs https://github.com/open-policy-agent/conftest/releases/download/v${VERSION}/checksums.txt && \ + curl -LOs "https://github.com/open-policy-agent/conftest/releases/download/v${VERSION}/conftest_${VERSION}_Linux_${CONFTEST_ARCH}.tar.gz" && \ + curl -LOs "https://github.com/open-policy-agent/conftest/releases/download/v${VERSION}/checksums.txt" && \ sed -n "/conftest_${VERSION}_Linux_${CONFTEST_ARCH}.tar.gz/p" checksums.txt | sha256sum -c && \ - mkdir -p /usr/local/bin/cft/versions/${VERSION} && \ - tar -C /usr/local/bin/cft/versions/${VERSION} -xzf conftest_${VERSION}_Linux_${CONFTEST_ARCH}.tar.gz && \ - ln -s /usr/local/bin/cft/versions/${VERSION}/conftest /usr/local/bin/conftest${VERSION} && \ - rm conftest_${VERSION}_Linux_${CONFTEST_ARCH}.tar.gz && \ + mkdir -p "/usr/local/bin/cft/versions/${VERSION}" && \ + tar -C "/usr/local/bin/cft/versions/${VERSION}" -xzf "conftest_${VERSION}_Linux_${CONFTEST_ARCH}.tar.gz" && \ + ln -s "/usr/local/bin/cft/versions/${VERSION}/conftest" "/usr/local/bin/conftest${VERSION}" && \ + rm "conftest_${VERSION}_Linux_${CONFTEST_ARCH}.tar.gz" && \ rm checksums.txt; \ done From a2373ad24a7ae5ef934237aec37b357167dd07d3 Mon Sep 17 00:00:00 2001 From: nitrocode <7775707+nitrocode@users.noreply.github.com> Date: Wed, 25 Jan 2023 20:23:55 -0600 Subject: [PATCH 04/11] wip --- .github/workflows/atlantis-image.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/atlantis-image.yml b/.github/workflows/atlantis-image.yml index b54f3cf29a..7078294421 100644 --- a/.github/workflows/atlantis-image.yml +++ b/.github/workflows/atlantis-image.yml @@ -21,7 +21,7 @@ jobs: build: strategy: matrix: - image_type: [alpine, debian] + image_type: [alpine] # , debian] runs-on: ubuntu-22.04 env: RELEASE_TYPE: ${{ contains(github.ref, 'pre') && 'pre' || 'stable' }} @@ -30,15 +30,18 @@ jobs: IMAGE_SUFFIX: ${{ matrix.image_type != 'alpine' && format('-{0}', matrix.image_type) || '' }} steps: - uses: actions/checkout@v3 + if: false - name: Set up QEMU uses: docker/setup-qemu-action@v2 + if: false with: image: tonistiigi/binfmt:latest platforms: arm64,arm - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 + if: false # related issues for pinning buildkit # https://github.com/docker/build-push-action/issues/761 # https://github.com/containerd/containerd/issues/7972 @@ -56,10 +59,12 @@ jobs: labels: | org.opencontainers.image.licenses=Apache-2.0 tags: | + type=raw,value=dev type=ref,event=branch type=ref,event=pr - type=semver,pattern={{version}},value=dev + type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} + type=schedule,pattern={{date 'YYYYMMDD'}} - name: Login to Packages Container registry uses: docker/login-action@v2 From c83acca81608cb4a3d40e00c66160ea579c40cef Mon Sep 17 00:00:00 2001 From: nitrocode <7775707+nitrocode@users.noreply.github.com> Date: Wed, 25 Jan 2023 20:27:32 -0600 Subject: [PATCH 05/11] wip --- .github/workflows/atlantis-image.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/atlantis-image.yml b/.github/workflows/atlantis-image.yml index 7078294421..15dfe63723 100644 --- a/.github/workflows/atlantis-image.yml +++ b/.github/workflows/atlantis-image.yml @@ -76,8 +76,7 @@ jobs: # Publish dev image to container registry - name: Build and push atlantis:dev${{ env.IMAGE_SUFFIX }} image - if: false - # if: ${{ contains(fromJson('["push", "pull_request"]'), github.event_name) }} + if: ${{ contains(fromJson('["push", "pull_request"]'), github.event_name) }} uses: docker/build-push-action@v3 with: cache-from: type=gha @@ -85,7 +84,7 @@ jobs: context: . build-args: | ATLANTIS_BASE_TAG_TYPE=${{ matrix.image_type }} - ATLANTIS_VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} + ATLANTIS_VERSION=dev ATLANTIS_COMMIT=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }} ATLANTIS_DATE=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }} platforms: linux/arm64/v8,linux/amd64,linux/arm/v7 @@ -113,7 +112,11 @@ jobs: cache-from: type=gha cache-to: type=gha,mode=max context: . - build-args: ATLANTIS_BASE_TAG_TYPE=${{ matrix.image_type }} + build-args: | + ATLANTIS_BASE_TAG_TYPE=${{ matrix.image_type }} + ATLANTIS_VERSION=dev + ATLANTIS_COMMIT=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }} + ATLANTIS_DATE=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }} platforms: linux/arm64/v8,linux/amd64,linux/arm/v7 push: ${{ github.event_name != 'pull_request' }} # release version is the name of the tag i.e. v0.10.0 From 8ab99fd493c01d456c8ac3af2061b6f5849b9d08 Mon Sep 17 00:00:00 2001 From: nitrocode <7775707+nitrocode@users.noreply.github.com> Date: Wed, 25 Jan 2023 20:28:03 -0600 Subject: [PATCH 06/11] wip --- .github/workflows/atlantis-image.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/atlantis-image.yml b/.github/workflows/atlantis-image.yml index 15dfe63723..2c3a68e830 100644 --- a/.github/workflows/atlantis-image.yml +++ b/.github/workflows/atlantis-image.yml @@ -28,20 +28,18 @@ jobs: RELEASE_TAG: ${{ contains(github.ref, 'pre') && 'prerelease-latest' || 'latest' }} IMAGE_BASE: ghcr.io/${{ github.repository_owner }}/atlantis IMAGE_SUFFIX: ${{ matrix.image_type != 'alpine' && format('-{0}', matrix.image_type) || '' }} + steps: - uses: actions/checkout@v3 - if: false - name: Set up QEMU uses: docker/setup-qemu-action@v2 - if: false with: image: tonistiigi/binfmt:latest platforms: arm64,arm - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - if: false # related issues for pinning buildkit # https://github.com/docker/build-push-action/issues/761 # https://github.com/containerd/containerd/issues/7972 @@ -68,7 +66,6 @@ jobs: - name: Login to Packages Container registry uses: docker/login-action@v2 - if: false with: registry: ghcr.io username: ${{ github.actor }} From 2e50a43a84385c7758030ec07eac6fd8c12a8e24 Mon Sep 17 00:00:00 2001 From: nitrocode <7775707+nitrocode@users.noreply.github.com> Date: Wed, 25 Jan 2023 20:32:59 -0600 Subject: [PATCH 07/11] wip --- .github/workflows/atlantis-image.yml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/atlantis-image.yml b/.github/workflows/atlantis-image.yml index 2c3a68e830..b44d1adc61 100644 --- a/.github/workflows/atlantis-image.yml +++ b/.github/workflows/atlantis-image.yml @@ -62,7 +62,6 @@ jobs: type=ref,event=pr type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} - type=schedule,pattern={{date 'YYYYMMDD'}} - name: Login to Packages Container registry uses: docker/login-action@v2 @@ -93,17 +92,16 @@ jobs: # Publish release to container registry - name: Populate release version - if: false - # if: | - # contains(fromJson('["push", "pull_request"]'), github.event_name) && - # startsWith(github.ref, 'refs/tags/') + if: | + contains(fromJson('["push", "pull_request"]'), github.event_name) && + startsWith(github.ref, 'refs/tags/') run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV - name: "Build and push atlantis:${{ env.RELEASE_VERSION }} image for ${{ env.RELEASE_TYPE }} release" if: false - # if: | - # contains(fromJson('["push", "pull_request"]'), github.event_name) && - # startsWith(github.ref, 'refs/tags/') + if: | + contains(fromJson('["push", "pull_request"]'), github.event_name) && + startsWith(github.ref, 'refs/tags/') uses: docker/build-push-action@v3 with: cache-from: type=gha From 6039341870a4258476bf7cea44125c6b31067bc5 Mon Sep 17 00:00:00 2001 From: nitrocode <7775707+nitrocode@users.noreply.github.com> Date: Wed, 25 Jan 2023 20:33:58 -0600 Subject: [PATCH 08/11] wip --- .github/workflows/atlantis-image.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/atlantis-image.yml b/.github/workflows/atlantis-image.yml index b44d1adc61..a5c3697bce 100644 --- a/.github/workflows/atlantis-image.yml +++ b/.github/workflows/atlantis-image.yml @@ -98,7 +98,6 @@ jobs: run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV - name: "Build and push atlantis:${{ env.RELEASE_VERSION }} image for ${{ env.RELEASE_TYPE }} release" - if: false if: | contains(fromJson('["push", "pull_request"]'), github.event_name) && startsWith(github.ref, 'refs/tags/') From 736ba3e9ddcc89d13a86b0ef739ba418fdd046b8 Mon Sep 17 00:00:00 2001 From: nitrocode <7775707+nitrocode@users.noreply.github.com> Date: Wed, 25 Jan 2023 20:48:12 -0600 Subject: [PATCH 09/11] wip --- .github/workflows/atlantis-image.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/atlantis-image.yml b/.github/workflows/atlantis-image.yml index a5c3697bce..5bdfbb50d3 100644 --- a/.github/workflows/atlantis-image.yml +++ b/.github/workflows/atlantis-image.yml @@ -21,7 +21,7 @@ jobs: build: strategy: matrix: - image_type: [alpine] # , debian] + image_type: [alpine, debian] runs-on: ubuntu-22.04 env: RELEASE_TYPE: ${{ contains(github.ref, 'pre') && 'pre' || 'stable' }} @@ -57,7 +57,6 @@ jobs: labels: | org.opencontainers.image.licenses=Apache-2.0 tags: | - type=raw,value=dev type=ref,event=branch type=ref,event=pr type=semver,pattern={{version}} @@ -108,7 +107,7 @@ jobs: context: . build-args: | ATLANTIS_BASE_TAG_TYPE=${{ matrix.image_type }} - ATLANTIS_VERSION=dev + ATLANTIS_VERSION=${{ env.RELEASE_VERSION }} ATLANTIS_COMMIT=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }} ATLANTIS_DATE=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }} platforms: linux/arm64/v8,linux/amd64,linux/arm/v7 From 0ad602ecbc49e05501b8ba3ebc4b61a279049ee2 Mon Sep 17 00:00:00 2001 From: nitrocode <7775707+nitrocode@users.noreply.github.com> Date: Wed, 25 Jan 2023 21:12:42 -0600 Subject: [PATCH 10/11] wip --- .goreleaser.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 7875ea4248..1e19596c0f 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -17,7 +17,6 @@ archives: format: zip files: - none* - rlcp: true checksum: name_template: 'checksums.txt' From c47c300c964a0203b2d1ebc909f9a5ea89709c31 Mon Sep 17 00:00:00 2001 From: nitrocode <7775707+nitrocode@users.noreply.github.com> Date: Wed, 25 Jan 2023 21:36:44 -0600 Subject: [PATCH 11/11] wip --- .github/workflows/release.yml | 1 + .goreleaser.yml | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index eaf2884241..7f7476739b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,6 +5,7 @@ on: tags: - v*.*.* # stable release like, v0.19.2 - v*.*.*-pre.* # pre release like, v0.19.0-pre.calendardate + workflow_dispatch: jobs: goreleaser: diff --git a/.goreleaser.yml b/.goreleaser.yml index 1e19596c0f..b937a3da07 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -25,10 +25,6 @@ changelog: skip: true release: - github: - owner: runatlantis - name: atlantis - # If set to true, will not auto-publish the release. # Default is false. draft: false