This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
190 lines (169 loc) · 6.69 KB
/
release_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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
name: Build and Release Docker Artifact
on:
push:
branches:
- main
tags:
- v[0-9].[0-9]+.[0-9]+
jobs:
build:
name: Build wash docker image
runs-on: ${{ matrix.config.os }}
outputs:
version_output: ${{ steps.version_output.outputs.version }}
strategy:
matrix:
config:
# NOTE: We are building on an older version of ubuntu because of libc compatibility
# issues. Namely, if we build on a new version of libc, it isn't backwards compatible with
# old versions. But if we build on the old version, it is compatible with the newer
# versions running in ubuntu 22 and its ilk
- os: "ubuntu-20.04"
arch: "amd64"
extension: ""
targetPath: "target/release/"
- os: "ubuntu-20.04"
arch: "aarch64"
extension: ""
targetPath: "target/aarch64-unknown-linux-gnu/release/"
steps:
- uses: actions/checkout@v4
- name: Set the release version (tag)
if: startsWith(github.ref, 'refs/tags/v')
shell: bash
run: echo "RELEASE_VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
- name: Set the release version (main)
if: github.ref == 'refs/heads/main'
shell: bash
run: echo "RELEASE_VERSION=canary" >> $GITHUB_ENV
- name: Output Version
id: version_output
run: echo "version=$RELEASE_VERSION" >> $GITHUB_OUTPUT
- name: Lowercase the runner OS name
shell: bash
run: |
OS=$(echo "${{ runner.os }}" | tr '[:upper:]' '[:lower:]')
echo "RUNNER_OS=$OS" >> $GITHUB_ENV
- name: Install latest Rust stable toolchain
uses: dtolnay/rust-toolchain@stable
if: matrix.config.arch != 'aarch64'
with:
toolchain: stable
components: clippy, rustfmt
- name: Setup for cross-compile builds
if: matrix.config.arch == 'aarch64' && matrix.config.os == 'ubuntu-20.04'
run: |
sudo apt-get update
sudo apt install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
rustup toolchain install stable-aarch64-unknown-linux-gnu
rustup target add --toolchain stable-aarch64-unknown-linux-gnu aarch64-unknown-linux-gnu
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
echo "CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
echo "CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++" >> $GITHUB_ENV
- name: Install latest Rust stable toolchain
uses: dtolnay/rust-toolchain@stable
if: matrix.config.arch == 'aarch64' && matrix.config.os == 'ubuntu-20.04'
with:
toolchain: stable
components: clippy, rustfmt
target: aarch64-unknown-linux-gnu
- name: Build release
if: matrix.config.arch != 'aarch64'
run: "cargo build --release"
- name: Build release
if: matrix.config.arch == 'aarch64' && matrix.config.os == 'ubuntu-20.04'
run: "cargo build --release --target aarch64-unknown-linux-gnu"
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: wash-${{ env.RELEASE_VERSION }}-${{ env.RUNNER_OS }}-${{ matrix.config.arch }}
if-no-files-found: error
path: |
${{ matrix.config.targetPath }}wash${{ matrix.config.extension }}
publish_images:
name: Publish docker image
runs-on: ubuntu-latest
needs: build
permissions:
packages: write
env:
RELEASE_VERSION: ${{ needs.build.outputs.version_output }}
# Annotations cause issues with the image metadata
# as displayed on GitHub packages page for the repo ('unknown/unknown')
#
# See: https://github.com/orgs/community/discussions/45969
BUILDX_NO_DEFAULT_ATTESTATIONS: 1
steps:
- uses: actions/checkout@v4
# Download all artifacts artifacts
- uses: actions/download-artifact@v3
with:
path: ./artifacts
# AzureCR login
- uses: azure/docker-login@v1
if: github.repository == 'wasmCloud/wash'
with:
login-server: ${{ secrets.AZURECR_PUSH_URL }}
username: ${{ secrets.AZURECR_PUSH_USER }}
password: ${{ secrets.AZURECR_PUSH_PASSWORD }}
# DockerHub login
- uses: docker/login-action@v3
if: github.repository == 'wasmCloud/wash'
with:
username: ${{ secrets.DOCKERHUB_PUSH_USER }}
password: ${{ secrets.DOCKERHUB_PUSH_PASSWORD }}
# Github Registry login
#
# NOTE: unknown/unknown will show up due to a bug in GHCR
# see: https://github.com/orgs/community/discussions/45969
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# NOTE: order matters, other steps (in particular azure/docker-login)
# are capable of messing up the docker buildx configuration
#
# see: https://github.com/docker/build-push-action/issues/163#issuecomment-918590372
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Extract docker metadata
- name: Configure Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
wasmcloud/wash
wasmcloud.azurecr.io/wash
ghcr.io/wasmcloud/wash
tags: |
type=semver,pattern={{version}}
type=sha
flavor: |
latest=auto
labels: |
org.opencontainers.image.title=wash
org.opencontainers.image.description=WAsmcloud SHell
org.opencontainers.image.vendor=wasmCloud
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.version=${{ env.RELEASE_VERSION }}
# Build the docker image
- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
with:
build-args: |
BIN_AMD64=/artifacts/wash-${{ env.RELEASE_VERSION }}-linux-amd64/wash
BIN_ARM64=/artifacts/wash-${{ env.RELEASE_VERSION }}-linux-aarch64/wash
context: .
file: "Dockerfile"
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
push: ${{ github.repository == 'wasmCloud/wash' }}
tags: ${{ steps.meta.outputs.tags }}
# Display image digest
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}