Skip to content

docs: Add links to Docker Mailserver repository #17

docs: Add links to Docker Mailserver repository

docs: Add links to Docker Mailserver repository #17

name: Build and Publish Docker Image
on:
push:
branches: [ "master" ]
tags: [ 'v*.*.*' ]
pull_request:
branches: [ "master" ]
env:
IMAGE_NAME: dunajdev/docker-mailserver-gui
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
pull-requests: read # Needed for tj-actions/changed-files on PRs
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# Fetch history to compare files (important for PRs)
fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }}
- name: Check for relevant file changes
id: check_changes
uses: tj-actions/changed-files@v44 # Use a recent version
with:
files: |
backend/**
frontend/**
docker/**
Dockerfile
docker-compose.yml
.github/workflows/**
files_ignore: |
**.md
backend/db.json
# --- Conditional Steps ---
# Run subsequent steps only if relevant files were changed
- name: Set up Node.js
if: steps.check_changes.outputs.any_changed == 'true'
uses: actions/setup-node@v4
with:
node-version: '20' # Use a recent LTS version
- name: Install backend dependencies and check formatting
if: steps.check_changes.outputs.any_changed == 'true'
run: |
cd backend
npm ci
npm run format:check
- name: Install frontend dependencies and check formatting
if: steps.check_changes.outputs.any_changed == 'true'
run: |
cd frontend
npm ci
npm run format:check
- name: Set up Docker Buildx
if: steps.check_changes.outputs.any_changed == 'true'
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
# Also check if relevant files changed
if: steps.check_changes.outputs.any_changed == 'true' && github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract metadata for Docker
if: steps.check_changes.outputs.any_changed == 'true'
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,format=short
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
if: steps.check_changes.outputs.any_changed == 'true'
uses: docker/build-push-action@v5
with:
context: .
# Push condition remains the same, but the whole step is conditional
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max