Skip to content

Build and push an image of Crypter.Web to GitHub Container Registry #228

Build and push an image of Crypter.Web to GitHub Container Registry

Build and push an image of Crypter.Web to GitHub Container Registry #228

name: Build and push an image of Crypter.Web to GitHub Container Registry
on:
release:
types:
- published
workflow_dispatch:
inputs:
environment:
description: 'Define the environment name'
required: true
type: choice
options:
- production
- development
env:
registry: ghcr.io/${{ github.repository_owner }}
jobs:
build-and-push-web-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
project_root: Crypter.Web/
environment:
name: ${{ (github.event_name == 'workflow_dispatch' && github.event.inputs.environment) || 'production' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Replace tokens in configuration
working-directory: ${{ env.project_root }}
run: |
sed -i 's|${API_BASE_URL}|${{ vars.API_BASE_URL }}|g' wwwroot/appsettings.json
sed -i 's|${API_BASE_URL}|${{ vars.API_BASE_URL }}|g' wwwroot/appsettings.Development.json
- 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: ${{ env.registry }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
flavor: |
latest=${{ (github.event_name == 'workflow_dispatch' && 'true') || 'auto' }}
images: ${{ env.registry }}/${{ vars.WEB_IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./Crypter.Web/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}