-
Notifications
You must be signed in to change notification settings - Fork 2
96 lines (87 loc) · 2.49 KB
/
Copy pathdocker-image.yml
File metadata and controls
96 lines (87 loc) · 2.49 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
name: Docker Image
on:
push:
branches:
- main
paths:
- '.github/workflows/docker-image.yml'
- 'Cargo.lock'
- 'Cargo.toml'
- 'crates/**'
- 'packaging/docker/**'
- 'packaging/runtime-binaries.txt'
pull_request:
paths:
- '.github/workflows/docker-image.yml'
- 'Cargo.lock'
- 'Cargo.toml'
- 'crates/**'
- 'packaging/docker/**'
- 'packaging/runtime-binaries.txt'
workflow_dispatch:
inputs:
push_image:
description: Push image to GHCR
required: false
default: true
type: boolean
permissions:
contents: read
env:
IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/calciforge
jobs:
docker-image:
name: Build image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Build Docker image
shell: bash
run: |
set -euo pipefail
image="${IMAGE_NAME,,}"
docker build \
-f crates/calciforge/Dockerfile \
--build-arg CARGO_BUILD_JOBS=1 \
--build-arg CARGO_BUILD_PROFILE=docker \
-t "$image:sha-${GITHUB_SHA::12}" \
-t "$image:main" \
.
publish-image:
name: Publish image
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && (github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.push_image == true))
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Build Docker image
shell: bash
run: |
set -euo pipefail
image="${IMAGE_NAME,,}"
docker build \
-f crates/calciforge/Dockerfile \
--build-arg CARGO_BUILD_JOBS=1 \
--build-arg CARGO_BUILD_PROFILE=docker \
-t "$image:sha-${GITHUB_SHA::12}" \
-t "$image:main" \
.
- name: Log in to GHCR
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
echo "$GH_TOKEN" | docker login ghcr.io -u "$GITHUB_ACTOR" --password-stdin
- name: Push Docker image
shell: bash
run: |
set -euo pipefail
image="${IMAGE_NAME,,}"
docker push "$image:sha-${GITHUB_SHA::12}"
docker push "$image:main"