Skip to content

Add deploy step

Add deploy step #4312

Workflow file for this run

name: CI/CD
on:
push:
branches:
- ci-refactoring
- mainnet
- testnet
- dev
pull_request:
jobs:
build_base:
name: Build & Test
if: github.event_name != 'pull_request' || github.event.pull_request.head.ref != 'weblate-tr'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker image for base
uses: docker/build-push-action@v6
with:
push: ${{ (github.event_name == 'push') && (github.ref == 'refs/heads/mainnet' || github.ref == 'refs/heads/testnet' || github.ref == 'refs/heads/ci-refactoring') }}
file: ./docker/Dockerfile.base
context: .
tags: ghcr.io/planb-network/blms-base:${{ github.sha }}
cache-from: type=gha,scope=global
cache-to: type=gha,mode=max,scope=global
build_api:
name: Build API
if: (github.event_name == 'push') && (github.ref == 'refs/heads/mainnet' || github.ref == 'refs/heads/testnet' || github.ref == 'refs/heads/ci-refactoring')
runs-on: ubuntu-latest
needs: build_base
env:
image: ghcr.io/planb-network/blms-api
base: ghcr.io/planb-network/blms-base:${{ github.sha }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set Docker image metadata
uses: docker/metadata-action@v5
id: meta
with:
images: ${{ env.image }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=sha,prefix=sha-
- name: Build and push Docker image for api
uses: docker/build-push-action@v6
with:
# push: ${{ (github.event_name == 'push') && (github.ref != 'refs/heads/ci-refactoring') }}
push: true
file: ./apps/api/docker/Dockerfile
context: .
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha,scope=global
cache-to: type=gha,mode=max,scope=global
build-args:
BASE_IMAGE=${{ env.base }}
build_web:
name: Build Web
if: (github.event_name == 'push') && (github.ref == 'refs/heads/mainnet' || github.ref == 'refs/heads/testnet' || github.ref == 'refs/heads/ci-refactoring')
runs-on: ubuntu-latest
needs: build_base
env:
image: ghcr.io/planb-network/blms-web
base: ghcr.io/planb-network/blms-base:${{ github.sha }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set Docker image metadata for web
uses: docker/metadata-action@v5
id: meta
with:
images: ${{ env.image }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=sha,prefix=sha-
- name: Build and push Docker image for web
uses: docker/build-push-action@v6
with:
# push: ${{ (github.event_name == 'push') && (github.ref != 'refs/heads/ci-refactoring') }}
push: true
file: ./apps/web/docker/Dockerfile
context: .
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha,scope=global
cache-to: type=gha,mode=max,scope=global
build-args:
BASE_IMAGE=${{ env.base }}
deploy:
name: Deploy
if: (github.event_name == 'push') && (github.ref == 'refs/heads/mainnet' || github.ref == 'refs/heads/testnet')
runs-on: ubuntu-latest
needs:
- build_api
- build_web
steps:
- name: Prepare compose file with environment variables
run: |
if [ "${GITHUB_REF}" = "refs/heads/mainnet" ]; then
sed -i 's/planbenvtoreplace/mainnet/g' docker/compose.yml
else
sed -i 's/planbenvtoreplace/testnet/g' docker/compose.yml
fi
env:
GITHUB_REF: ${{ github.ref }}
- name: Copy Docker files to server
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
source: 'docker/compose.yml,docker/cdn'
overwrite: true
strip_components: 1
target: ${{ github.ref == 'refs/heads/mainnet' && 'mainnet' || 'testnet' }}
- name: Deploy to server
uses: appleboy/ssh-action@v1.2.0
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
script_stop: true
script: |
cd ${{ github.ref == 'refs/heads/mainnet' && 'mainnet' || 'testnet' }}
docker compose pull
docker compose stop || true
docker compose rm -f || true
docker compose up -d