Deploy to production #37
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: Deploy to production | |
concurrency: | |
group: deploy-prod | |
cancel-in-progress: false | |
on: | |
release: | |
types: [ published ] | |
workflow_dispatch: | |
jobs: | |
deploy: | |
environment: production | |
runs-on: ubuntu-22.04 | |
name: Deploy to production | |
env: | |
DOCKER_REGISTRY: ghcr.io | |
REPO_NAME: ${{ github.event.repository.name }} | |
REPO_OWNER: ${{ github.repository_owner }} | |
TARGET_DIR_ON_SERVER: /blumilk/production | |
steps: | |
- name: checkout | |
uses: actions/[email protected] | |
- name: set deployment project version | |
run: echo "DEPLOYMENT_PROJECT_VERSION=$(bash ./environment/prod/deployment/scripts/version.sh --long)" >> $GITHUB_ENV | |
- name: set up Docker Buildx | |
uses: docker/[email protected] | |
- name: login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.DOCKER_REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ github.token }} | |
- name: Docker meta | |
id: meta | |
uses: docker/[email protected] | |
with: | |
images: ${{ env.DOCKER_REGISTRY }}/${{ github.repository_owner }}/${{ env.REPO_NAME }} | |
tags: | | |
type=raw,value=latest | |
context: workflow | |
- name: build and push image | |
uses: docker/[email protected] | |
with: | |
context: . | |
file: ./environment/prod/app/Dockerfile | |
build-args: DEPLOYMENT_PROJECT_VERSION_ARG=${{ env.DEPLOYMENT_PROJECT_VERSION }} | |
push: true | |
labels: ${{ steps.meta.outputs.labels }} | |
tags: ${{ steps.meta.outputs.tags }} | |
cache-from: type=gha, ref=${{ env.DOCKER_REGISTRY }}/${{ github.repository_owner }}/${{ env.REPO_NAME }}-prod-build-cache | |
cache-to: type=gha, ref=${{ env.DOCKER_REGISTRY }}/${{ github.repository_owner }}/${{ env.REPO_NAME }}-prod-build-cache, mode=max | |
- name: copy files via ssh | |
uses: appleboy/[email protected] | |
with: | |
timeout: 10s | |
command_timeout: 10m | |
host: ${{ secrets.VPS_OVH_BF7EC892_HOST }} | |
port: ${{ secrets.VPS_OVH_BF7EC892_PORT }} | |
username: ${{ secrets.VPS_OVH_BF7EC892_USERNAME }} | |
key: ${{ secrets.VPS_OVH_BF7EC892_SSH_PRIVATE_KEY }} | |
passphrase: ${{ secrets.VPS_OVH_BF7EC892_SSH_PRIVATE_KEY_PASSPHRASE }} | |
source: "./environment/prod/deployment/prod/*,./environment/prod/deployment/scripts/*" | |
target: ${{ env.TARGET_DIR_ON_SERVER }}/${{ env.REPO_NAME }} | |
rm: true | |
- uses: appleboy/[email protected] | |
with: | |
timeout: 10s | |
command_timeout: 10m | |
host: ${{ secrets.VPS_OVH_BF7EC892_HOST }} | |
port: ${{ secrets.VPS_OVH_BF7EC892_PORT }} | |
username: ${{ secrets.VPS_OVH_BF7EC892_USERNAME }} | |
key: ${{ secrets.VPS_OVH_BF7EC892_SSH_PRIVATE_KEY }} | |
passphrase: ${{ secrets.VPS_OVH_BF7EC892_SSH_PRIVATE_KEY_PASSPHRASE }} | |
script_stop: true | |
script: | | |
cd ${{ env.TARGET_DIR_ON_SERVER }}/${{ env.REPO_NAME }}/environment/prod/deployment/prod | |
make prod-deploy SOPS_AGE_KEY=${{ secrets.SOPS_AGE_PROD_SECRET_KEY }} | |
docker images --filter dangling=true | grep "${{ env.DOCKER_REGISTRY }}/${{ env.REPO_OWNER }}/${{ env.REPO_NAME }}" | awk '{print $3}'| xargs --no-run-if-empty docker rmi |