chore(ci): Print if env vars are null #17
Workflow file for this run
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: Production | |
on: | |
push: | |
branches: [main, ci-aws] | |
env: | |
AWS_REGION: ap-southeast-2 | |
jobs: | |
lint-format: | |
name: Linting Checks | |
uses: ./.github/workflows/lint.yml | |
build: | |
needs: lint-format | |
name: Build | |
runs-on: [self-hosted, ARM64] # Since deployment is on arm64 | |
environment: Production | |
permissions: | |
id-token: write | |
contents: read | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install Docker Compose | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y docker-compose | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} | |
role-session-name: ${{ secrets.AWS_ROLE_SESSION_NAME }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Build Docker container | |
run: | | |
docker buildx build \ | |
--platform=linux/arm64 --file=Dockerfile -t duckbot . | |
docker image save duckbot | gzip > duckbot.tar.gz | |
- name: Copy image and compose file to S3 | |
run: | | |
aws s3 cp ./duckbot.tar.gz s3://${{ secrets.AWS_S3_BUCKET }}/duckbot/ | |
aws s3 cp ./docker-compose.yml s3://${{ secrets.AWS_S3_BUCKET }}/duckbot/ | |
deploy: | |
needs: build | |
name: Deploy | |
runs-on: ubuntu-latest | |
environment: Production | |
steps: | |
- name: Deploy on EC2 | |
env: | |
KEY: ${{ secrets.SSH_EC2_KEY }} | |
HOSTNAME: ${{ secrets.SSH_EC2_HOSTNAME }} | |
USER: ${{ secrets.SSH_EC2_USER }} | |
GUILD_ID: ${{ secrets.GUILD_ID }} | |
BOT_TOKEN: ${{ secrets.BOT_TOKEN }} | |
run: | | |
echo "$KEY" > private_key && chmod 600 private_key | |
ssh -v -o StrictHostKeyChecking=no -i private_key ${USER}@${HOSTNAME} ' | |
cd ~/duckbot | |
aws s3 cp s3://${{ secrets.AWS_S3_BUCKET }}/duckbot/duckbot.tar.gz . | |
aws s3 cp s3://${{ secrets.AWS_S3_BUCKET }}/duckbot/docker-compose.yml . | |
if [ -z "$GUILD_ID" ]; then | |
echo "GUILD_ID is null" | |
else | |
echo "GUILD_ID is not null" | |
fi | |
if [ -z "$BOT_TOKEN" ]; then | |
echo "BOT_TOKEN is null" | |
else | |
echo "BOT_TOKEN is not null" | |
fi | |
echo GUILD_ID=${GUILD_ID} > .env | |
echo BOT_TOKEN=${BOT_TOKEN} >> .env | |
docker load -i duckbot.tar.gz | |
docker compose up -d | |
' |