From 93d11c02a624c02d96bd64983fb5d4630a1e16b1 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Fri, 26 Jan 2024 21:02:17 +0000 Subject: [PATCH] Migrate to woodpecker (#150) # Description Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. - Migrate to Woodpecker CI > **NOTE:** This will require the Drone project to be disabled before merge! #122 ## Type of change Please delete options that are not relevant. - [x] New feature (non-breaking change which adds functionality) # How Has This Been Tested? Please describe the tests that you ran to verify the changes. Provide instructions so we can reproduce. Please also list any relevant details to your test configuration. # Checklist - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that provde my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules Reviewed-on: https://gitea.vylpes.xyz/External/card-drop/pulls/150 Reviewed-by: VylpesTester Co-authored-by: Ethan Lane Co-committed-by: Ethan Lane --- .woodpecker.yml | 47 +++++++++++++++++++++++++++++++++++++++++ scripts/deploy_prod.sh | 23 +++++--------------- scripts/deploy_stage.sh | 23 +++++--------------- 3 files changed, 57 insertions(+), 36 deletions(-) create mode 100644 .woodpecker.yml diff --git a/.woodpecker.yml b/.woodpecker.yml new file mode 100644 index 0000000..30ac056 --- /dev/null +++ b/.woodpecker.yml @@ -0,0 +1,47 @@ +steps: + build: + image: node + commands: + - npm ci + - npm run build + when: + event: push + branch: [ hotfix/*, feature/*, renovate/*, develop, main ] + lint: + image: node + commands: + - npm run lint + when: + event: push + branch: [ hotfix/*, feature/*, renovate/*, develop, main ] + test: + image: node + commands: + - npm test + when: + event: push + branch: [ hotfix/*, feature/*, renovate/*, develop, main ] + stage: + image: alpine + secrets: [ ssh_key, stage_bot_token ] + commands: + - apk add rsync openssh-client + - eval `ssh-agent -s` + - echo "$SSH_KEY" | tr -d '\r' | ssh-add - + - rsync -e "ssh -o StrictHostKeyChecking=no" -r ./* vylpes@192.168.68.120:/home/vylpes/apps/card-drop/card-drop_stage + - ssh vylpes@192.168.68.120 BOT_TOKEN='$${stage_bot_token}' 'bash -s' < ./scripts/deploy_stage.sh + when: + event: push + branch: [ develop ] + deploy: + image: alpine + secrets: [ ssh_key, prod_bot_token ] + commands: + - apk add rsync openssh-client + - eval `ssh-agent -s` + - echo "$SSH_KEY" | tr -d '\r' | ssh-add - + - rsync -e "ssh -o StrictHostKeyChecking=no" -r ./* vylpes@192.168.68.120:/home/vylpes/apps/card-drop/card-drop_prod + - ssh vylpes@192.168.68.120 BOT_TOKEN='$${prod_bot_token}' 'bash -s' < ./scripts/deploy_prod.sh + when: + event: push + branch: [ main ] \ No newline at end of file diff --git a/scripts/deploy_prod.sh b/scripts/deploy_prod.sh index 0c7f799..84f35c6 100644 --- a/scripts/deploy_prod.sh +++ b/scripts/deploy_prod.sh @@ -3,21 +3,8 @@ export PATH="$HOME/.yarn/bin:$PATH" export PATH="$HOME/.nodeuse/bin:$PATH" -export BOT_TOKEN=$(cat $HOME/scripts/card-drop/prod_key.txt) - -cd ~/apps/card-drop/card-drop_prod \ -&& git checkout main \ -&& git fetch \ -&& git pull \ -&& docker compose --file docker-compose.prod.yml down \ -&& (pm2 stop card-drop_prod || true) \ -&& (pm2 delete card-drop_prod || true) \ -&& cp .prod.env .env \ -&& npm run clean \ -&& npm ci \ -&& npm run build \ -&& docker compose --file docker-compose.prod.yml up -d \ -&& echo "Sleeping for 10 seconds to let database load..." \ -&& sleep 10 \ -&& npm run db:up \ -&& NODE_ENV=production pm2 start --name card-drop_prod dist/bot.js \ No newline at end of file +cd ~/apps/card-drop/card-drop_prod +docker compose --file docker-compose.prod.yml up -d +sleep 10 +cp .prod.env .env +pm2 restart card-drop_prod || pm2 start --name card-drop_prod dist/bot.js \ No newline at end of file diff --git a/scripts/deploy_stage.sh b/scripts/deploy_stage.sh index 96fbbe6..9287b53 100644 --- a/scripts/deploy_stage.sh +++ b/scripts/deploy_stage.sh @@ -3,21 +3,8 @@ export PATH="$HOME/.yarn/bin:$PATH" export PATH="$HOME/.nodeuse/bin:$PATH" -export BOT_TOKEN=$(cat $HOME/scripts/card-drop/stage_key.txt) - -cd ~/apps/card-drop/card-drop_stage \ -&& git checkout develop \ -&& git fetch \ -&& git pull \ -&& docker compose --file docker-compose.stage.yml down \ -&& (pm2 stop card-drop_stage || true) \ -&& (pm2 delete card-drop_stage || true) \ -&& cp .stage.env .env \ -&& npm run clean \ -&& npm ci \ -&& npm run build \ -&& docker compose --file docker-compose.stage.yml up -d \ -&& echo "Sleeping for 10 seconds to let database load..." \ -&& sleep 10 \ -&& npm run db:up \ -&& NODE_ENV=production pm2 start --name card-drop_stage dist/bot.js \ No newline at end of file +cd ~/apps/card-drop/card-drop_stage +docker compose --file docker-compose.stage.yml up -d +sleep 10 +cp .stage.env .env +pm2 restart card-drop_stage || pm2 start --name card-drop_stage dist/bot.js \ No newline at end of file