-
Notifications
You must be signed in to change notification settings - Fork 11
114 lines (99 loc) · 3.34 KB
/
docker-publish.yml
File metadata and controls
114 lines (99 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
name: Docker Build and Publish
on:
pull_request:
branches: [ main ]
paths:
- 'src/**'
- 'Dockerfile.*'
- 'docker/**'
- '.github/workflows/docker-publish.yml'
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: 'Tag to build and push (e.g., v1.0.0 or latest)'
required: true
default: 'latest'
env:
REGISTRY: ghcr.io
IMAGE_NAME_API: ${{ github.repository }}/api
IMAGE_NAME_CATALOGSYNC: ${{ github.repository }}/catalogsync
jobs:
# Verify builds on PRs (no push)
verify-build:
name: Verify Docker Builds
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
strategy:
matrix:
service: [api, catalogsync]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build ${{ matrix.service }} (verification only)
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.${{ matrix.service }}
push: false
tags: purdueio-${{ matrix.service }}:test
cache-from: type=gha
cache-to: type=gha,mode=max
# Build and push on releases
build-and-push:
name: Build and Push Docker Images
runs-on: ubuntu-latest
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'
permissions:
contents: read
packages: write
strategy:
matrix:
include:
- service: api
image_name_var: IMAGE_NAME_API
- service: catalogsync
image_name_var: IMAGE_NAME_CATALOGSYNC
steps:
- name: Checkout code
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: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ matrix.service == 'api' && env.IMAGE_NAME_API || env.IMAGE_NAME_CATALOGSYNC }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=${{ github.event.inputs.tag }},enable=${{ github.event_name == 'workflow_dispatch' }}
- name: Build and push ${{ matrix.service }}
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.${{ matrix.service }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Output image tags
run: |
echo "### Published ${{ matrix.service }} image :rocket:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Tags:**" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY