chore: update Docker image configuration and enhance CI/CD workflow

- Changed the Docker image reference in docker-compose.yml to use dynamic environment variables for better flexibility.
- Updated the GitHub Actions workflow to set the image tag based on the commit SHA, ensuring unique tagging for each build.
- Added environment variable definitions for Docker Hub credentials and image tag in the deployment process.
This commit is contained in:
vchikalkin 2025-08-15 21:17:31 +03:00
parent 9f1b13192f
commit d9ac6858e7
2 changed files with 11 additions and 3 deletions

View File

@ -9,19 +9,25 @@ jobs:
build-and-push:
name: Build and Push to Docker Hub
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.vars.outputs.tag }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set image tag
id: vars
run: echo "tag=${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 image
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-strapi:latest .
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-strapi:${{ steps.vars.outputs.tag }} .
- name: Push image to Docker Hub
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-strapi:latest
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-strapi:${{ steps.vars.outputs.tag }}
deploy:
name: Deploy to VPS
@ -58,6 +64,8 @@ jobs:
echo "DATABASE_PASSWORD=${{ secrets.DATABASE_PASSWORD }}" >> .env
echo "DATABASE_SSL=false" >> .env
echo "BOT_TOKEN=${{ secrets.BOT_TOKEN }}" >> .env
echo "DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}" >> .env
echo "STRAPI_IMAGE_TAG=${{ needs.build-and-push.outputs.tag }}" >> .env
- name: Copy .env to VPS via SCP
uses: appleboy/scp-action@master

View File

@ -1,6 +1,6 @@
services:
strapi:
image: vchikalkin/zapishis-strapi:latest
image: ${DOCKERHUB_USERNAME}/zapishis-strapi:${STRAPI_IMAGE_TAG}
ports:
- "127.0.0.1:1337:1337"
environment: