Deploy #186
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" | |
on: | |
workflow_run: | |
workflows: ["Build and push packages"] | |
branches: | |
- "master" | |
- "*.*.*" | |
types: | |
- completed | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
SEMVER_REGEX: ^\d.\d.\d+(?:-(\w)+(:?.\d+)?)?$ | |
jobs: | |
stop: | |
runs-on: ubuntu-latest | |
if: github.event.workflow_run.conclusion == 'success' | |
steps: | |
- name: Stop | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ${{ secrets.SSH_USERNAME }} | |
key: ${{ secrets.SSH_KEY }} | |
port: ${{ secrets.SSH_PORT }} | |
script: | | |
docker stop $(docker ps -f name=pe-testnet-api -q) || true | |
docker stop $(docker ps -f name=pe-testnet-indexer -q) || true | |
docker rm pe-testnet-api pe-testnet-indexer || true | |
drop_db: | |
runs-on: ubuntu-latest | |
needs: stop | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: REGEX | |
uses: actions-ecosystem/action-regex-match@v2 | |
id: regex-match | |
with: | |
text: ${{ github.event.workflow_run.head_branch }} | |
regex: ${{env.SEMVER_REGEX}} | |
- name: Drop database | |
if: ${{steps.regex-match.outputs.match != ''}} | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ${{ secrets.SSH_USERNAME }} | |
key: ${{ secrets.SSH_KEY }} | |
port: ${{ secrets.SSH_PORT }} | |
script: | | |
git -C ./platform-explorer pull | |
docker pull owl352/refinery_cli_docker | |
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:api | |
docker run --rm --env-file testnet.env ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:api npm run db:drop | |
docker run --rm --env-file testnet.env -v ./platform-explorer/packages/indexer/migrations:/migrations owl352/refinery_cli_docker ./refinery migrate -e DATABASE_URL -p /migrations | |
start: | |
runs-on: ubuntu-latest | |
needs: drop_db | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Deploy to the server | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ${{ secrets.SSH_USERNAME }} | |
key: ${{ secrets.SSH_KEY }} | |
port: ${{ secrets.SSH_PORT }} | |
script: | | |
git -C ./platform-explorer pull | |
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:api | |
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:indexer | |
docker run -d -p 3005:3005 --restart always --env-file testnet.env --name pe-testnet-api ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:api | |
sleep 3 | |
docker run -d --env-file testnet.env --restart always --name pe-testnet-indexer ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:indexer ./indexer |