Update Docker images in docker-compose and GitHub Actions workflow to use dynamic tags
- Changed Docker image references in docker-compose.yml to utilize environment variables for versioning. - Updated GitHub Actions workflow to generate and use dynamic image tags based on the commit SHA for both web and bot images. - Ensured that the .env file is populated with the new image tags during the deployment process.
This commit is contained in:
parent
7d94521c8b
commit
b44d92cef3
20
.github/workflows/deploy.yml
vendored
20
.github/workflows/deploy.yml
vendored
@ -9,6 +9,9 @@ jobs:
|
||||
build-and-push:
|
||||
name: Build and Push to Docker Hub
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
web_tag: ${{ steps.vars.outputs.web_tag }}
|
||||
bot_tag: ${{ steps.vars.outputs.bot_tag }}
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
@ -23,24 +26,30 @@ jobs:
|
||||
echo "NEXTAUTH_SECRET=fakesecret" >> .env
|
||||
echo "BOT_URL=http://localhost:3000" >> .env
|
||||
|
||||
- name: Set image tags
|
||||
id: vars
|
||||
run: |
|
||||
echo "web_tag=web-${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
|
||||
echo "bot_tag=bot-${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Login to Docker Hub
|
||||
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin
|
||||
|
||||
- name: Build web image
|
||||
run: |
|
||||
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-web:latest -f ./apps/web/Dockerfile .
|
||||
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-web:${{ steps.vars.outputs.web_tag }} -f ./apps/web/Dockerfile .
|
||||
|
||||
- name: Push web image to Docker Hub
|
||||
run: |
|
||||
docker push ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-web:latest
|
||||
docker push ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-web:${{ steps.vars.outputs.web_tag }}
|
||||
|
||||
- name: Build bot image
|
||||
run: |
|
||||
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-bot:latest -f ./apps/bot/Dockerfile .
|
||||
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-bot:${{ steps.vars.outputs.bot_tag }} -f ./apps/bot/Dockerfile .
|
||||
|
||||
- name: Push bot image to Docker Hub
|
||||
run: |
|
||||
docker push ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-bot:latest
|
||||
docker push ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-bot:${{ steps.vars.outputs.bot_tag }}
|
||||
|
||||
deploy:
|
||||
name: Deploy to VPS
|
||||
@ -71,6 +80,9 @@ jobs:
|
||||
echo "EMAIL_GRAPHQL=${{ secrets.EMAIL_GRAPHQL }}" >> .env
|
||||
echo "NEXTAUTH_SECRET=${{ secrets.NEXTAUTH_SECRET }}" >> .env
|
||||
echo "BOT_URL=${{ secrets.BOT_URL }}" >> .env
|
||||
echo "WEB_IMAGE_TAG=${{ needs.build-and-push.outputs.web_tag }}" >> .env
|
||||
echo "BOT_IMAGE_TAG=${{ needs.build-and-push.outputs.bot_tag }}" >> .env
|
||||
echo "DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}" >> .env
|
||||
|
||||
- name: Copy .env to VPS via SCP
|
||||
uses: appleboy/scp-action@master
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
services:
|
||||
web:
|
||||
image: vchikalkin/zapishis-web:latest
|
||||
image: ${DOCKERHUB_USERNAME}/zapishis-web:${WEB_IMAGE_TAG}
|
||||
env_file:
|
||||
- .env
|
||||
restart: always
|
||||
@ -9,13 +9,12 @@ services:
|
||||
interval: 10s
|
||||
timeout: 3s
|
||||
retries: 5
|
||||
# ports:
|
||||
# - 3000:3000
|
||||
networks:
|
||||
- app
|
||||
- web
|
||||
|
||||
bot:
|
||||
image: vchikalkin/zapishis-bot:latest
|
||||
image: ${DOCKERHUB_USERNAME}/zapishis-bot:${BOT_IMAGE_TAG}
|
||||
env_file:
|
||||
- .env
|
||||
restart: always
|
||||
@ -27,4 +26,3 @@ networks:
|
||||
external: true
|
||||
web:
|
||||
external: true
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user