Created
December 26, 2023 18:54
-
-
Save i7N3/463d987e320cd60963d75c211e9f1009 to your computer and use it in GitHub Desktop.
GitHub Action to build and deploy arbitrage bot to GCP VM.
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: Build and Deploy to GCP VM | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
env: | |
PROJECT_ID: ${{ secrets.PROJECT_ID }} | |
GCLOUD_KEY: ${{ secrets.GCLOUD_KEY }} | |
STATIC_IP: ${{ secrets.STATIC_IP }} | |
BUCKET_NAME: ${{ secrets.BUCKET_NAME }} | |
BINANCE_API_KEY: ${{ secrets.BINANCE_API_KEY }} | |
BINANCE_SECRET: ${{ secrets.BINANCE_SECRET }} | |
KUCOIN_API_KEY: ${{ secrets.KUCOIN_API_KEY }} | |
KUCOIN_PASSWORD: ${{ secrets.KUCOIN_PASSWORD }} | |
KUCOIN_SECRET: ${{ secrets.KUCOIN_SECRET }} | |
OKX_API_KEY: ${{ secrets.OKX_API_KEY }} | |
OKX_PASSWORD: ${{ secrets.OKX_PASSWORD }} | |
OKX_SECRET: ${{ secrets.OKX_SECRET }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Authenticate with Google Cloud | |
uses: google-github-actions/auth@v1 | |
with: | |
credentials_json: ${{ env.GCLOUD_KEY }} | |
- name: Setup Google Cloud SDK | |
uses: google-github-actions/setup-gcloud@v1 | |
- name: Archive code | |
run: | | |
zip -r code.zip . | |
- name: Upload code to GCP Storage | |
run: | | |
gcloud storage cp code.zip gs://${{ env.BUCKET_NAME }}/code.zip | |
- name: Delete VM if exists | |
run: | | |
(gcloud compute instances describe bot --zone=asia-southeast1-a > /dev/null 2>&1 && gcloud compute instances delete bot --zone=asia-southeast1-a --quiet) || true | |
- name: Create VM instance | |
run: | | |
gcloud compute instances create bot --image-family ubuntu-2204-lts --image-project ubuntu-os-cloud --zone=asia-southeast1-a --machine-type=e2-micro --no-restart-on-failure --metadata google-logging-enabled=true,google-logging-use-fluentbit=true --metadata-from-file shutdown-script=shutdown.sh --scopes cloud-platform --service-account build-and-deploy@${{ env.PROJECT_ID }}.iam.gserviceaccount.com --address=${{ env.STATIC_IP }} | |
- name: Install unzip and pip3 on VM | |
run: | | |
gcloud compute ssh bot --zone=asia-southeast1-a --project=${{ env.PROJECT_ID }} --command "sudo apt update && sudo apt install python3-pip -y && sudo apt install unzip -y" | |
- name: Download code to VM | |
run: | | |
gcloud compute ssh bot --zone=asia-southeast1-a --project=${{ env.PROJECT_ID }} --command "gsutil cp gs://${{ env.BUCKET_NAME }}/code.zip code.zip && unzip code.zip -d code" | |
- name: Install code dependencies on VM | |
run: | | |
gcloud compute ssh bot --zone=asia-southeast1-a --project=${{ env.PROJECT_ID }} --command "cd code && pip3 install --no-cache-dir -r requirements.txt" | |
- name: Run code | |
run: | | |
gcloud compute ssh bot --zone=asia-southeast1-a --project=${{ env.PROJECT_ID }} --command "export BINANCE_API_KEY=$(printf '%q' '${{ env.BINANCE_API_KEY }}') && export BINANCE_SECRET=$(printf '%q' '${{ env.BINANCE_SECRET }}') && export KUCOIN_API_KEY=$(printf '%q' '${{ env.KUCOIN_API_KEY }}') && export KUCOIN_PASSWORD=$(printf '%q' '${{ env.KUCOIN_PASSWORD }}') && export KUCOIN_SECRET=$(printf '%q' '${{ env.KUCOIN_SECRET }}') && export OKX_API_KEY=$(printf '%q' '${{ env.OKX_API_KEY }}') && export OKX_PASSWORD=$(printf '%q' '${{ env.OKX_PASSWORD }}') && export OKX_SECRET=$(printf '%q' '${{ env.OKX_SECRET }}') && export GCLOUD_KEY=$(printf '%q' '${{ env.GCLOUD_KEY }}') && tmux new -d -s botsession 'python3 code/main.py'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment