-
Notifications
You must be signed in to change notification settings - Fork 6
80 lines (70 loc) · 2.34 KB
/
Copy pathreusable-docker.yml
File metadata and controls
80 lines (70 loc) · 2.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
# Builds the batchee Docker image on PRs and pushes.
name: Reusable docker workflow
on:
workflow_call:
inputs:
push:
type: boolean
required: false
default: false
env:
PYTHON_VERSION: "3.12"
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Retrieve repository
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Set up uv
uses: astral-sh/setup-uv@v7
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Determine version
id: version
run: |
SERVICE_VERSION="$(uv tool run hatch version)"
if [[ "${SERVICE_VERSION}" =~ rc[0-9]+$ ]]; then
target_env=uat
else
target_env=ops
fi
echo "service_version=${SERVICE_VERSION}" >> "$GITHUB_OUTPUT"
echo "target_env=$target_env" >> "$GITHUB_OUTPUT"
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ steps.version.outputs.service_version }}
type=raw,value=${{ steps.version.outputs.target_env }}
type=raw,value=latest,enable=${{ steps.version.outputs.target_env == 'ops' }}
- name: Log in to the Container registry
if: ${{ inputs.push }}
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build and push Docker image
uses: docker/build-push-action@v7
with:
context: .
file: Dockerfile
build-args: |
SERVICE_VERSION=${{ steps.version.outputs.service_version }}
push: ${{ inputs.push }}
pull: true
platforms: linux/amd64
provenance: false
sbom: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=${{ (github.head_ref || github.ref_name) }}
cache-to: type=gha,mode=max,scope=${{ (github.head_ref || github.ref_name) }}