Merge pull request #68 from Project-Betoniera/dev #173
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker Image CI/CD | |
on: | |
push: | |
branches: | |
- main | |
- dev | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Setup Docker buildx | |
uses: docker/setup-buildx-action@v3 | |
# Login against a Docker registry | |
# https://github.com/docker/login-action | |
- name: Log into Docker Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GHCR_TOKEN }} | |
# Extract metadata (tags, labels) for Docker | |
# https://github.com/docker/metadata-action | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
# Build and push Docker image with Buildx (don't push on PR) | |
# https://github.com/docker/build-push-action | |
- name: Build and push Docker image | |
id: build-and-push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
platforms: linux/arm64/v8,linux/amd64 | |
file: ./Dockerfile | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
build-args: | | |
API_URL=${{ vars.API_URL }} | |
PLAUSIBLE_DOMAIN=${{ vars.PLAUSIBLE_DOMAIN }} | |
IS_BETA_BUILD=${{ vars.IS_BETA_BUILD }} | |
COMMIT_SHA=${{ github.sha }} | |
deploy_to_server: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- if: github.ref == 'refs/heads/main' | |
name: Deploy to production server | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ vars.SSH_HOST }} | |
username: ${{ vars.SSH_USERNAME }} | |
key: ${{ secrets.KEY }} | |
port: ${{ vars.SSH_PORT }} | |
script: | | |
docker stop project-betoniera-frontend | |
docker rm project-betoniera-frontend | |
docker rmi ghcr.io/project-betoniera/project-betoniera-frontend:main | |
docker pull ghcr.io/project-betoniera/project-betoniera-frontend:main | |
docker run -t -d --restart unless-stopped -p 4200:80 --sig-proxy=false --name project-betoniera-frontend ghcr.io/project-betoniera/project-betoniera-frontend:main |