Skip to content

CI(*): Automated Push to Docker Registry #1

CI(*): Automated Push to Docker Registry

CI(*): Automated Push to Docker Registry #1

Workflow file for this run

name: Docker Build and Push
on:
push:
branches: [ main ]
env:
DOCKER_REGISTRY: docker.io
BACKEND_IMAGE_NAME: ${{ secrets.DOCKER_USERNAME }}/your-app-backend
FRONTEND_IMAGE_NAME: ${{ secrets.DOCKER_USERNAME }}/your-app-frontend
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Generate build timestamp
id: timestamp
run: echo "timestamp=$(date +'%Y%m%d_%H%M%S')" >> $GITHUB_OUTPUT
- name: Build and push backend image
uses: docker/build-push-action@v4
with:
context: .
file: Dockerfile.prod
push: true
tags: |
${{ env.BACKEND_IMAGE_NAME }}:latest
${{ env.BACKEND_IMAGE_NAME }}:${{ github.sha }}
${{ env.BACKEND_IMAGE_NAME }}:${{ steps.timestamp.outputs.timestamp }}
cache-from: type=registry,ref=${{ env.BACKEND_IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.BACKEND_IMAGE_NAME }}:buildcache,mode=max