Skip to content

Commit

Permalink
fix(docker): Set version based on release tag, revert gorelease signi…
Browse files Browse the repository at this point in the history
…ng (runatlantis#3051)

* fix(docker): Set version based on release tag, revert gorelease signing
  • Loading branch information
nitrocode authored Jan 26, 2023
1 parent 89ccb86 commit 40f1e95
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 19 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/atlantis-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ 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

Expand Down Expand Up @@ -76,7 +77,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' }}
tags: |
Expand All @@ -100,7 +105,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=${{ 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
push: ${{ github.event_name != 'pull_request' }}
# release version is the name of the tag i.e. v0.10.0
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 6 additions & 8 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -47,10 +43,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"
24 changes: 16 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
Expand Down

0 comments on commit 40f1e95

Please sign in to comment.