-
Notifications
You must be signed in to change notification settings - Fork 117
124 lines (118 loc) · 4.38 KB
/
docker.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
name: Build Docker images
on:
push:
branches: [main]
schedule:
- cron: '42 7 * * *' # run at 7:42 UTC (morning) every day
permissions:
contents: read
env:
RUST_IMAGE_TAG: latest
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
DOCKER_REPO: ${{ secrets.DOCKERHUB_USERNAME }}/cargo-chef
jobs:
rust_image_tag_matrix:
name: Generate Rust Docker image tag matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
-
id: set-matrix
run: |
(echo -n 'matrix=[' \
&& curl --silent https://raw.githubusercontent.com/docker-library/official-images/master/library/rust \
| grep -E Tags: \
| cut -d ' ' -f 2- \
| sed 's/, /\n/g' \
| sed 's/\(.*\)/"\1",/g' \
| tr '\n' ' ' \
| sed '$ s/..$//' \
&& echo ']') >> "$GITHUB_OUTPUT"
build_and_push:
name: Build and push
needs: [rust_image_tag_matrix]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
rust_image_tag: ${{fromJSON(needs.rust_image_tag_matrix.outputs.matrix)}}
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
# Get package version from git tags
name: Get package version
id: package_version
run: |-
git fetch --tags
VER=$(git tag --sort="-v:refname" | head -n 1 | cut -d"v" -f2)
echo "result=$VER" >> "$GITHUB_OUTPUT"
-
# Check if version matches ^\d+\.\d+\.\d+$
name: Determine if release version
id: is_release_version
run: |
if [[ ${{ steps.package_version.outputs.result }} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "result=true" >> "$GITHUB_OUTPUT"
fi
-
name: Determine if duplicated
id: is_duplicated
run: |
CHEF_IMAGE=$DOCKER_REPO:$CHEF_IMAGE_TAG
CHEF_IMAGE_TAG=$CHEF_PACKAGE_VERSION-rust-$RUST_IMAGE_TAG
if DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect $CHEF_IMAGE >/dev/null; then
echo "There is already a pushed image with ${CHEF_IMAGE_TAG} as tag. Skipping."
echo "result=true" >> "$GITHUB_OUTPUT"
else
echo "result=false" >> "$GITHUB_OUTPUT"
fi
-
name: Build and push without `latest` tag
if: ${{ steps.is_release_version.outputs.result == 'true' && steps.is_duplicated.outputs.result == 'false' && matrix.rust_image_tag != 'latest' }}
run: |
RUST_IMAGE_TAG=${{ matrix.rust_image_tag }}
CHEF_PACKAGE_VERSION=${{ steps.package_version.outputs.result }}
CHEF_IMAGE=$DOCKER_REPO:$CHEF_PACKAGE_VERSION-rust-$RUST_IMAGE_TAG
CHEF_IMAGE_LATEST=$DOCKER_REPO:latest-rust-$RUST_IMAGE_TAG
docker buildx build \
--tag $CHEF_IMAGE \
--tag $CHEF_IMAGE_LATEST \
--build-arg=BASE_IMAGE=rust:$RUST_IMAGE_TAG \
--build-arg=CHEF_TAG=$CHEF_PACKAGE_VERSION \
--platform linux/amd64,linux/arm64 \
--push \
./docker
-
# Latest Rust version, latest cargo-chef version
name: Build and push with `latest` tag
if: ${{ steps.is_release_version.outputs.result == 'true' && steps.is_duplicated.outputs.result == 'false' && matrix.rust_image_tag == 'latest' }}
run: |
RUST_IMAGE_TAG=${{ matrix.rust_image_tag }}
CHEF_PACKAGE_VERSION=${{ steps.package_version.outputs.result }}
CHEF_IMAGE=$DOCKER_REPO:$CHEF_PACKAGE_VERSION-rust-$RUST_IMAGE_TAG
CHEF_IMAGE_LATEST=$DOCKER_REPO:latest-rust-$RUST_IMAGE_TAG
docker buildx build \
--tag $CHEF_IMAGE \
--tag $CHEF_IMAGE_LATEST \
--tag $DOCKER_REPO:latest \
--build-arg=BASE_IMAGE=rust:$RUST_IMAGE_TAG \
--build-arg=CHEF_TAG=$CHEF_PACKAGE_VERSION \
--platform linux/amd64,linux/arm64 \
--push \
./docker