Skip to content

build-and-deploy-trading-bot-am #4

build-and-deploy-trading-bot-am

build-and-deploy-trading-bot-am #4

name: build-and-deploy-trading-bot-am
on: workflow_dispatch
jobs:
build:
runs-on: ubuntu-latest
name: Build images
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/upload-artifact@v4
with:
name: docker-compose-file
path: ./docker-compose-prod.yml
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Restore cached npm dependencies
uses: actions/cache/restore@v3
with:
path: |
node_modules
~/.cache/Cypress # needed for the Cypress binary
key: npm-dependencies-${{ hashFiles('package.json') }}
- name: Install dependencies
run: pnpm install
if: steps.cache.outputs.cache-hit != 'true'
- name: Cache npm dependencies
uses: actions/cache/save@v3
with:
path: |
node_modules
~/.cache/Cypress # needed for the Cypress binary
key: npm-dependencies-${{ hashFiles('package.json') }}
- name: Build image for trading-bot-am
run: docker build -t registry.digitalocean.com/maxdata/trading-bot-am:latest -f ./Dockerfile . --platform=linux/amd64
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Log in to DO Container Registry
# 30min
run: doctl registry login --expiry-seconds 1800
- name: Push image to DO Container Registry
run: docker push registry.digitalocean.com/maxdata/trading-bot-am:latest
deploy:
runs-on: ubuntu-latest
name: Deploy trading bot
needs: ['build']
steps:
- name: donwload docker-compose-file
uses: actions/download-artifact@v4
with:
name: docker-compose-file
path: trading_bot
- name: copy file via ssh password
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.VPS_IP }}
username: root
key: ${{ secrets.SSH_PASSPHRASE_PRIVATE_KEY }}
passphrase: ${{ secrets.SSH_PASSPHRASE }}
port: 22
envs: DIR,ENV
source: "trading_bot/docker-compose-prod.yml"
target: ./
# target: trading_bot
- name: Connect to VPS and refresh docker compose
env:
DIR: trading_bot # Replace with your target directory
ENV: prod # Replace with your environment
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.VPS_IP }}
username: root
key: ${{ secrets.SSH_PASSPHRASE_PRIVATE_KEY }}
passphrase: ${{ secrets.SSH_PASSPHRASE }}
port: 22
envs: DIR,ENV
script: |
cd $DIR
docker-compose pull
docker-compose up -d --no-deps --build trading-bot-am
docker image prune -f
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
# - name: Log in to DO Container Registry
# # 30min
# run: doctl registry login --expiry-seconds 1800
# - name: Clear DO container registry
# run: doctl registry garbage-collection start --force linkerry