Skip to content

Merge pull request #172 from Femcoders-SleepUp/dev #16

Merge pull request #172 from Femcoders-SleepUp/dev

Merge pull request #172 from Femcoders-SleepUp/dev #16

Workflow file for this run

# Build workflow - Automatically builds and pushes Docker images on main branch pushes
# This workflow runs whenever code is pushed to the main branch
name: Build
# Trigger: Run on pushes to the main branch only
on:
push:
branches:
- main
jobs:
build:
# Use the latest Ubuntu runner for consistent environment
runs-on: ubuntu-latest
steps:
# Step 1: Check out the repository code
- uses: actions/checkout@v4
# Step 2: Set up Docker Buildx for advanced Docker builds
# Buildx enables multi-platform builds and advanced caching
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Step 3: Authenticate with Docker Hub
# Uses secrets stored in GitHub repository settings
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# Step 4: Generate Docker image metadata and tags
# Creates tags based on branch name and commit SHA
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKER_USERNAME }}/sleepUp
tags: |
type=ref,event=branch # Tag with branch name (e.g., main)
type=sha,prefix=sha- # Tag with commit SHA (e.g., sha-abc123)
# Step 5: Build and push the Docker image
# Uses GitHub Actions cache for faster subsequent builds
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: . # Build context is the repository root
file: ./Dockerfile # Dockerfile location
push: true # Push to Docker Hub after building
tags: ${{ steps.meta.outputs.tags }} # Use tags generated in previous step
labels: ${{ steps.meta.outputs.labels }} # Add metadata labels
cache-from: type=gha # Use GitHub Actions cache for layers
cache-to: type=gha,mode=max # Save all layers to cache