GreenStack Starter GitHub Actions Workflow Print

  • 0

You can find a starter GitHub Actions Workflow below; you are free to add your frontend build steps to the file.

name: Build and Push Docker Image

on:
  push:
    branches: [main, master]
  workflow_dispatch:

env:
  REGISTRY: ghcr.io
  IMAGE_NAME: USERNAME/REPOSITORY-NAME

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write

    steps:
      - uses: actions/checkout@v4

      - name: Log in to GHCR
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Generate timestamp
        id: timestamp
        run: echo "tag=$(date +'%H%M%S%d%m%Y')" >> $GITHUB_OUTPUT

      - uses: microsoft/variable-substitution@v1 
        with:
          files: 'UmbracoProject.Web/appsettings.Production.json'
        env:
          ConnectionStrings.umbracoDbDSN: ${{ secrets.CONNECTION_STRING }}

      - name: Build and push
        working-directory: ./
        run: |
          docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.timestamp.outputs.tag }} .
          docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.timestamp.outputs.tag }} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
          docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.timestamp.outputs.tag }}
          docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
          echo "Published: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.timestamp.outputs.tag }}"

Was this answer helpful?

« Back