Skip to content

Commit c669e36

Browse files
committed
Use ghcr.io to store the images
The images are always built, but only pushed to the registry when running on the master branch. Signed-off-by: Gaëtan Lehmann <[email protected]>
1 parent 2d5b016 commit c669e36

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

.github/workflows/docker.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Build and Push Docker Image to GHCR
2+
3+
on: push
4+
5+
permissions:
6+
contents: read # Required to checkout the repo code
7+
packages: write # Required to push packages to GHCR
8+
9+
jobs:
10+
xcp-ng-build-env-82:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: docker/setup-buildx-action@v3
15+
with:
16+
driver: docker-container
17+
- uses: docker/login-action@v3
18+
if: github.ref == 'refs/heads/master'
19+
with:
20+
registry: ghcr.io
21+
username: ${{ github.actor }} # Uses the GitHub user/org name that triggered the workflow
22+
password: ${{ secrets.GITHUB_TOKEN }} # Automatically provided by GitHub
23+
- uses: docker/build-push-action@v5 # Using v5 for latest features
24+
with:
25+
context: ./src/xcp_ng_dev/
26+
file: ./src/xcp_ng_dev/files/Dockerfile-8.x
27+
push: ${{ github.ref == 'refs/heads/master' }}
28+
tags: ghcr.io/${{ github.repository }}:8.2
29+
cache-from: type=gha,scope=${{ github.ref_name }}-82 # Cache layers to speed up builds
30+
cache-to: type=gha,mode=max,scope=${{ github.ref_name }}-82 # Store layers in cache for future builds
31+
build-args: |
32+
XCP_NG_BRANCH=8.2
33+
platforms: |
34+
linux/amd64
35+
36+
xcp-ng-build-env-83:
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v4
40+
- uses: docker/setup-buildx-action@v3
41+
with:
42+
driver: docker-container
43+
- uses: docker/login-action@v3
44+
if: github.ref == 'refs/heads/master'
45+
with:
46+
registry: ghcr.io
47+
username: ${{ github.actor }} # Uses the GitHub user/org name that triggered the workflow
48+
password: ${{ secrets.GITHUB_TOKEN }} # Automatically provided by GitHub
49+
- uses: docker/build-push-action@v5 # Using v5 for latest features
50+
with:
51+
context: ./src/xcp_ng_dev/
52+
file: ./src/xcp_ng_dev/files/Dockerfile-8.x
53+
push: ${{ github.ref == 'refs/heads/master' }}
54+
tags: ghcr.io/${{ github.repository }}:8.3
55+
cache-from: type=gha,scope=${{ github.ref_name }}-83 # Cache layers to speed up builds
56+
cache-to: type=gha,mode=max,scope=${{ github.ref_name }}-83 # Store layers in cache for future builds
57+
platforms: |
58+
linux/amd64
59+
60+
# TODO: uncomment once we have a public xcp-ng 9.0 repository
61+
# xcp-ng-build-env-90:
62+
# runs-on: ubuntu-latest
63+
# steps:
64+
# - uses: actions/checkout@v4
65+
# - uses: docker/setup-buildx-action@v3
66+
# with:
67+
# driver: docker-container
68+
# - uses: docker/login-action@v3
69+
# if: github.ref == 'refs/heads/master'
70+
# with:
71+
# registry: ghcr.io
72+
# username: ${{ github.actor }} # Uses the GitHub user/org name that triggered the workflow
73+
# password: ${{ secrets.GITHUB_TOKEN }} # Automatically provided by GitHub
74+
# - uses: docker/build-push-action@v5 # Using v5 for latest features
75+
# with:
76+
# context: ./src/xcp_ng_dev/
77+
# file: ./src/xcp_ng_dev/files/Dockerfile-9.x
78+
# platforms: |
79+
# linux/amd64/v2
80+
# push: ${{ github.ref == 'refs/heads/master' }}
81+
# tags: ghcr.io/${{ github.repository }}:9.0
82+
# cache-from: type=gha,scope=${{ github.ref_name }}-90 # Cache layers to speed up builds
83+
# cache-to: type=gha,mode=max,scope=${{ github.ref_name }}-90 # Store layers in cache for future builds

0 commit comments

Comments
 (0)