From b4f57003b880031e0f0d3f707ae6338d4f8437cd Mon Sep 17 00:00:00 2001 From: Phoenix Isaac Pereira Date: Wed, 5 Jun 2024 22:20:50 +0930 Subject: [PATCH] chore(ci): Update production workflow to fix environment variables --- .github/workflows/production.yml | 15 +++++---------- Dockerfile | 9 +++------ 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/.github/workflows/production.yml b/.github/workflows/production.yml index 8fb4d03..74d2b7f 100644 --- a/.github/workflows/production.yml +++ b/.github/workflows/production.yml @@ -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 @@ -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 ' diff --git a/Dockerfile b/Dockerfile index 6e0b3aa..28e9246 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"]