Skip to content

Commit

Permalink
chore(ci): Update production workflow to fix environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenixpereira committed Jun 5, 2024
1 parent e1808b2 commit b4f5700
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
15 changes: 5 additions & 10 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,9 @@ jobs:
role-session-name: ${{ secrets.AWS_ROLE_SESSION_NAME }}
aws-region: ${{ env.AWS_REGION }}

# - name: Install arm64 support for Docker
# run: docker run --privileged --rm tonistiigi/binfmt --install arm64

- name: Build Docker container
env:
GUILD_ID: ${{ secrets.GUILD_ID }}
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
run: |
docker buildx build \
--secret id=GUILD_ID \
--secret id=BOT_TOKEN \
--platform=linux/arm64 --file=Dockerfile -t duckbot .
docker image save duckbot | gzip > duckbot.tar.gz
Expand All @@ -61,13 +53,16 @@ jobs:
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 .
echo GUILD_ID=${GUILD_ID} > .env
echo BOT_TOKEN=${BOT_TOKEN} >> .env
docker load -i duckbot.tar.gz
docker compose up -d
docker restart duckbot
docker compose up -d --env-file .env
'
9 changes: 3 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ COPY pyproject.toml poetry.lock ./

RUN pip install poetry \
&& poetry config virtualenvs.create false \
&& poetry install --no-dev
&& poetry install --no-dev --no-interaction --no-ansi

# Copy the rest of the application code
COPY . .

# Set environment variables during runtime
CMD ["sh", "-c", \
"GUILD_ID=$(cat /run/secrets/GUILD_ID) && \
BOT_TOKEN=$(cat /run/secrets/BOT_TOKEN) && \
poetry run python src/main.py"]
# Run the bot
CMD ["poetry", "run", "python", "src/main.py"]

0 comments on commit b4f5700

Please sign in to comment.