Skip to content

Build and deploy

Build and deploy #14

Workflow file for this run

name: Build and deploy
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-build-deploy
cancel-in-progress: true
on:
workflow_call:
workflow_dispatch:
jobs:
env:
runs-on: ubuntu-latest
steps:
- name: Derive environment from git ref
id: environment
run: |
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
ENVIRONMENT="production"
APP_NAME_SUFFIX=""
elif [ "${{ github.ref }}" = "refs/heads/develop" ]; then
ENVIRONMENT="development"
APP_NAME_SUFFIX="-development"
elif [ "${{github.event_name}}" = "pull_request"]; then
ENVIRONMENT="pr/${{ github.event.pull_request.number }}"
APP_NAME_SUFFIX="-pr-${{ github.event.pull_request.number }}"
else
exit 1
fi
echo "ENVIRONMENT=$ENVIRONMENT" >> $GITHUB_OUTPUT
echo "APP_NAME_SUFFIX=$APP_NAME_SUFFIX" >> $GITHUB_OUTPUT
outputs:
environment: "${{ steps.environment.outputs.ENVIRONMENT }}"
app_name: "mmp-frontend${{ steps.environment.outputs.APP_NAME_SUFFIX }}"
registry: ghcr.io
image: ${{ github.repository }}
vars:
needs: [env]
runs-on: ubuntu-latest
environment:
name: ${{ needs.env.outputs.environment }}
steps:
- name: Generate public URL
id: public_url
run: |
if [ -z "${{ vars.PUBLIC_URL }}" ]; then
PUBLIC_URL="https://${{ needs.env.outputs.app_name }}.${{ vars.KUBE_INGRESS_BASE_DOMAIN }}"
else
PUBLIC_URL="${{ vars.PUBLIC_URL }}"
fi
echo "PUBLIC_URL=$PUBLIC_URL" >> $GITHUB_OUTPUT
outputs:
public_url: ${{ steps.public_url.outputs.PUBLIC_URL }}
build:
needs: [env, vars]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ needs.env.outputs.registry }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ needs.env.outputs.registry }}/${{ needs.env.outputs.image }}
tags: |
type=raw,value={{sha}}
type=ref,event=branch
# type=ref,event=pr
# type=semver,pattern={{version}}
# type=semver,pattern={{major}}.{{minor}}
# type=raw,value=latest
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
"VITE_APP_API_BASE_URL=${{ vars.K8S_SECRET_NUXT_PUBLIC_API_BASE_URL }}"
"VITE_APP_BASE_URL=${{ needs.vars.outputs.public_url }}"
"VITE_APP_MATOMO_BASE_URL=${{ vars.NUXT_PUBLIC_MATOMO_BASE_URL }}"
"VITE_APP_MATOMO_ID=${{ vars.NUXT_PUBLIC_MATOMO_ID }}"
"VITE_APP_REDMINE_ID=${{ vars.K8S_SECRET_SERVICE_ID }}"
cache-from: type=gha
cache-to: type=gha,mode=max
deploy:
needs: [env, vars, build]
uses: acdh-oeaw/gl-autodevops-minimal-port/.github/workflows/deploy.yml@main
secrets: inherit
with:
environment: ${{ needs.env.outputs.environment }}
DOCKER_TAG: ${{ needs.env.outputs.registry }}/${{ needs.env.outputs.image }}
APP_NAME: "${{ needs.env.outputs.app_name }}"
APP_ROOT: "/"
SERVICE_ID: "${{ vars.SERVICE_ID }}"
PUBLIC_URL: "${{ needs.vars.outputs.public_url }}"
default_port: "3000"