forked from TrafeX/docker-php-nginx
-
Notifications
You must be signed in to change notification settings - Fork 27
105 lines (89 loc) · 3.43 KB
/
build.yml
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
name: buildx
on:
push:
pull_request:
jobs:
buildx:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the code
- name: Checkout
uses: actions/checkout@v4
# Step 2: Prepare variables for building and tagging the image
- name: Prepare
id: prepare
run: |
GHCR_IMAGE=ghcr.io/${GITHUB_REPOSITORY}
DOCKER_PLATFORMS=linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386,linux/ppc64le,linux/s390x
VERSION=$(echo ${GITHUB_REF#refs/*/} | sed 's/\//-/g') # Replace / with - in tag name
TAGS="${GITHUB_REPOSITORY}:${VERSION}"
if [[ $GITHUB_REF == refs/tags/* ]]; then
TAGS="$TAGS,${GITHUB_REPOSITORY}:latest"
elif [[ $VERSION == "master" ]]; then
TAGS="$TAGS,${GITHUB_REPOSITORY}:beta"
fi
GHCR_TAGS="${GHCR_IMAGE}:${VERSION}"
if [[ $GITHUB_REF == refs/tags/* ]]; then
GHCR_TAGS="$GHCR_TAGS,${GHCR_IMAGE}:latest"
elif [[ $VERSION == "master" ]]; then
GHCR_TAGS="$GHCR_TAGS,${GHCR_IMAGE}:beta"
fi
echo "platforms=${DOCKER_PLATFORMS}" >> $GITHUB_OUTPUT
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "ghcr-tags=${GHCR_TAGS}" >> $GITHUB_OUTPUT
# Step 3: Set up QEMU for multi-platform builds
- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@v3
with:
image: tonistiigi/binfmt:latest
platforms: all
# Step 4: Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
id: buildx
# Step 5: Login to DockerHub
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# Step 5.5: Login to GitHub Container Registry
- name: Login to GHCR
if: github.event_name != 'pull_request'
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
# Step 6: Debug Build
- name: Debug Build on PR
run: |
docker buildx build --load .
# Step 7: Test the built image
- name: Test
run: |
docker-compose version
docker-compose --file docker-compose.test.yml up --exit-code-from sut --timeout 10 --build
# Step 8: Build and Push (if not a PR)
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prepare.outputs.tags }}
platforms: ${{ steps.prepare.outputs.platforms }}
# Step 9: Push to GitHub Container Registry
- name: Push to GHCR
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.prepare.outputs.ghcr-tags }}
platforms: ${{ steps.prepare.outputs.platforms }}
# Step 10: Update Docker Hub Description
- name: Docker Hub Description
if: startsWith(github.ref, 'refs/tags/')
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
short-description: ${{ github.event.repository.description }}