Files
my-website-v2/.github/workflows/build.yaml
2025-07-19 16:52:14 -04:00

105 lines
3.2 KiB
YAML

name: Build and Release Docker Images
on:
push:
branches: [master]
pull_request:
branches: [master]
workflow_dispatch:
env:
REGISTRY: scm.wyattjmiller.com
USERNAME: wymiller # Define username here to use consistently
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
include:
- dockerfile: public/Dockerfile
image: my-website-v2_public
context: ./backend
- dockerfile: task/Dockerfile
image: my-website-v2_task
context: ./backend
- dockerfile: Dockerfile
image: my-website-v2_frontend
context: ./frontend
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.GH_ACTION_USERNAME }}
password: ${{ secrets.GH_ACTION_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: scm.wyattjmiller.com/wymiller/${{ matrix.image }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ${{ matrix.context }}
file: ${{ matrix.context }}/${{ matrix.dockerfile }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64
create-release:
if: startsWith(github.ref, 'refs/tags/')
needs: build-and-push
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_ACTION_TOKEN }}
with:
tag_name: ${{ github.ref_name }}
release_name: Release ${{ github.ref_name }}
body: |
## Docker Images Released
The following Docker images have been built and pushed to the container registry:
- `${{ env.REGISTRY }}/${{ env.USERNAME }}/my-website-v2_public:${{ github.ref_name }}`
- `${{ env.REGISTRY }}/${{ env.USERNAME }}/my-website-v2_task:${{ github.ref_name }}`
- `${{ env.REGISTRY }}/${{ env.USERNAME }}/my-website-v2_frontend:${{ github.ref_name }}`
### Usage
```bash
docker pull ${{ env.REGISTRY }}/${{ env.USERNAME }}/my-website-v2_public:${{ github.ref_name }}
docker pull ${{ env.REGISTRY }}/${{ env.USERNAME }}/my-website-v2_task:${{ github.ref_name }}
docker pull ${{ env.REGISTRY }}/${{ env.USERNAME }}/my-website-v2_frontend:${{ github.ref_name }}
```
draft: false
prerelease: false