Skip to content

Merge branch 'feat/context-update' of github.com:Genio2003/Project-Be… #139

Merge branch 'feat/context-update' of github.com:Genio2003/Project-Be…

Merge branch 'feat/context-update' of github.com:Genio2003/Project-Be… #139

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@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
# Login against a Docker registry
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
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@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
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@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
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 }}
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: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }}
script: |
docker stop project-betoniera-frontend
docker rm project-betoniera-frontend
docker rmi ghcr.io/genio2003/project-betoniera-frontend:main
docker pull ghcr.io/genio2003/project-betoniera-frontend:main
docker run -t -d --restart unless-stopped -p 4200:80 --sig-proxy=false --name project-betoniera-frontend ghcr.io/genio2003/project-betoniera-frontend:main