Skip to content

Deploy prod

Deploy prod #29

Workflow file for this run

name: Build and Deploy
on:
workflow_dispatch:
push:
branches:
- 'main'
- 'staging'
tags:
- 'v*'
pull_request:
branches:
- 'main'
- 'staging'
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/Dockerfile
target: 'prod'
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
needs: build
strategy:
matrix:
include:
- environment: staging
branch: staging
target_path: "~/staging.mapdb.cncnet.org"
compose_file: "docker-compose.prod.yml"
nginx_conf: "docker/nginx.prod.conf"
host: ${{ secrets.STAGING_SSH_HOST }}

Check failure on line 67 in .github/workflows/cd.yml

View workflow run for this annotation

GitHub Actions / Build and Deploy

Invalid workflow file

The workflow is not valid. .github/workflows/cd.yml (Line: 67, Col: 19): Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.STAGING_SSH_HOST .github/workflows/cd.yml (Line: 73, Col: 19): Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.PROD_SSH_HOST
- environment: production
branch: main
target_path: "~/mapdb.cncnet.org"
compose_file: "docker-compose.prod.yml"
nginx_conf: "docker/nginx.prod.conf"
host: ${{ secrets.PROD_SSH_HOST }}
steps:
- name: "Exit if not matching branch"
if: github.ref != format('refs/heads/{0}', matrix.branch)
run: echo "Not target branch for this deployment. Skipping..." && exit 0
- name: Checkout repository
uses: actions/checkout@v4
- name: Copy docker-compose and nginx config over ssh
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ matrix.host }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: "${{ matrix.compose_file }},${{ matrix.nginx_conf }}"
target: "${{ matrix.target_path }}"
- name: SSH into server and deploy
uses: appleboy/ssh-action@v1.2.1
with:
host: ${{ matrix.host }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd ${{ matrix.target_path }}
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
echo "${{ secrets.PROD_FULL_ENV_FILE }}" > .env
docker compose -f ${{ matrix.compose_file }} pull
docker compose -f ${{ matrix.compose_file }} down
docker compose -f ${{ matrix.compose_file }} up -d