Skip to content

Commit

Permalink
ci(GH Action): use environment variables instead of outputs (#339)
Browse files Browse the repository at this point in the history
* use environment variables instead of outputs

* add build information in docker-compose

* replace more outputs with env vars

* set default values

* Replace last output variable

* add info about the issue

* apply prettier
  • Loading branch information
hf-krechan authored Dec 19, 2024
1 parent 91cfb99 commit b45d1b2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
42 changes: 27 additions & 15 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ env:
IMAGE_NAME: ${{ github.repository }}
PROJECT_NAME: ahb-tabellen
OCTOPUS_SPACE: Default
BUILD_DATE: "set by build_release_info step"
COMMIT_ID: "set by build_release_info step"
VERSION_TAG: "set by build_release_info step"
DOCKER_METADATA_OUTPUT_TAGS: "set by metadata action"
DOCKER_METADATA_OUTPUT_LABELS: "set by metadata action"
DIGEST: "set by output of push step"

on:
release:
Expand All @@ -28,10 +34,9 @@ jobs:
BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
COMMIT_ID=$(git rev-parse HEAD)
VERSION_TAG=${GITHUB_REF#refs/tags/}
echo "::set-output name=build_date::$BUILD_DATE"
echo "::set-output name=commit_id::$COMMIT_ID"
echo "::set-output name=version_tag::$VERSION_TAG"
echo "::set-output name=prerelease::${{ github.event.release.prerelease }}"
echo "BUILD_DATE=$BUILD_DATE" >> $GITHUB_ENV
echo "COMMIT_ID=$COMMIT_ID" >> $GITHUB_ENV
echo "VERSION_TAG=$VERSION_TAG" >> $GITHUB_ENV
- name: Log in to the Container registry
uses: docker/login-action@v3.3.0
Expand All @@ -52,18 +57,25 @@ jobs:
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ env.DOCKER_METADATA_OUTPUT_TAGS }}
labels: ${{ env.DOCKER_METADATA_OUTPUT_LABELS }}
build-args: |
BUILD_DATE=${{ steps.build_release_info.outputs.build_date }}
COMMIT_ID=${{ steps.build_release_info.outputs.commit_id }}
VERSION=${{ steps.build_release_info.outputs.version_tag }}
BUILD_DATE=${{ env.BUILD_DATE }}
COMMIT_ID=${{ env.COMMIT_ID }}
VERSION=${{ env.VERSION_TAG }}
# The build-push-action does not output the digest as environment variable only as output.
# But the output way is deprecated. So we need to set it manually
# https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
# I opened an issue in the build-push-action repository: https://github.com/docker/build-push-action/issues/1285
- name: Set DIGEST environment variable
run: echo "DIGEST=${{ steps.push.outputs.digest }}" >> $GITHUB_ENV

- name: Generate artifact attestation
uses: actions/attest-build-provenance@v2
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
subject-digest: ${{ steps.push.outputs.digest }}
subject-digest: ${{ env.DIGEST }}
push-to-registry: true

- name: Login to Octopus Deploy 🐙
Expand All @@ -77,21 +89,21 @@ jobs:
with:
space: ${{ env.OCTOPUS_SPACE }}
project: ${{ env.PROJECT_NAME }}
release_number: ${{ steps.build_release_info.outputs.version_tag }}
release_number: ${{ env.VERSION_TAG }}
git_ref: ${{ github.ref }}
git_commit: ${{ github.sha }}
release_notes: "Release created from GitHub Actions. Version: ${{ steps.build_release_info.outputs.version_tag }}"
release_notes: "Release created from GitHub Actions. Version: ${{ env.VERSION_TAG }}"

- name: Deploy a release in Octopus Deploy 🐙
uses: OctopusDeploy/deploy-release-action@v3
with:
space: ${{ env.OCTOPUS_SPACE }}
project: ${{ env.PROJECT_NAME }}
release_number: ${{ steps.build_release_info.outputs.version_tag }}
release_number: ${{ env.VERSION_TAG }}
environments: |
Staging
- name: Notify for Production Deployment Approval
if: ${{ steps.build_release_info.outputs.prerelease == 'false' }}
if: ${{ github.event.release.prerelease == 'false' }}
run: |
echo "Release ${{ steps.build_release_info.outputs.version_tag }} created. Awaiting manual approval for production deployment."
echo "Release ${{ env.VERSION_TAG }} created. Awaiting manual approval for production deployment."
8 changes: 8 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@ services:
server:
build:
dockerfile: ./Dockerfile
context: .
args:
BUILD_DATE: ${BUILD_DATE}
COMMIT_ID: ${COMMIT_ID}
VERSION: ${VERSION}
ports:
- 4000:4000
environment:
- PORT=4000
- AZURE_BLOB_STORAGE_CONNECTION_STRING=DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://host.docker.internal:10000/devstoreaccount1;
- AHB_CONTAINER_NAME=uploaded-files
- FORMAT_VERSION_CONTAINER_NAME=format-versions
- BUILD_DATE=foo
- COMMIT_ID=bar
- VERSION=v1.0.0
depends_on:
- upload-documents
- azurite

0 comments on commit b45d1b2

Please sign in to comment.