-
Notifications
You must be signed in to change notification settings - Fork 14
171 lines (148 loc) · 5.61 KB
/
containerize-and-push.yaml
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
# ********************************************************************************
# Copyright (c) 2024 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************/
name: Containerize uStreamer and Push to Container Registry
on:
push:
branches:
- main
pull_request:
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/zenoh-mqtt-streamer
jobs:
setup:
runs-on: ubuntu-latest
outputs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
steps:
- name: Extract metadata and create tag
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
build-arm64:
needs: setup
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
digest: ${{ steps.build_and_push.outputs.digest }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker buildx
uses: docker/setup-buildx-action@v3
- name: Login to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Install Rust and Cross
uses: ./.github/actions/setup-rust-cross
- name: Cross Build for arm64
working-directory: example-streamer-implementations
run: |
cross build --target aarch64-unknown-linux-musl --bin zenoh_mqtt --features="zenoh-transport mqtt-transport" --release
- name: Fix Registry and Repository names
shell: bash
run: |
echo "REGISTRY=$(echo $REGISTRY | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
echo "IMAGE_NAME=$(echo $IMAGE_NAME | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Build and push Docker image for arm64
id: build_and_push
uses: docker/build-push-action@v5
with:
context: .
file: "Dockerfile.zenoh-mqtt-arm"
push: true
platforms: linux/arm64
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:arm64-${{ github.sha }}
labels: ${{ needs.setup.outputs.labels }}
build-amd64:
needs: setup
runs-on: ubuntu-latest
outputs:
digest: ${{ steps.build_and_push.outputs.digest }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker buildx
uses: docker/setup-buildx-action@v3
- name: Login to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Install Rust and Cross
uses: ./.github/actions/setup-rust-cross
- name: Cross Build for amd64
working-directory: example-streamer-implementations
run: |
cross build --target x86_64-unknown-linux-musl --bin zenoh_mqtt --features="zenoh-transport mqtt-transport" --release
- name: Fix Registry and Repository names
shell: bash
run: |
echo "REGISTRY=$(echo $REGISTRY | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
echo "IMAGE_NAME=$(echo $IMAGE_NAME | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Build and push Docker image for amd64
id: build_and_push
uses: docker/build-push-action@v5
with:
context: .
file: "Dockerfile.zenoh-mqtt-amd"
push: true
platforms: linux/amd64
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:amd64-${{ github.sha }}
labels: ${{ needs.setup.outputs.labels }}
create-manifest:
needs: [setup, build-arm64, build-amd64]
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Login to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Fix Registry and Repository names
shell: bash
run: |
echo "REGISTRY=$(echo $REGISTRY | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
echo "IMAGE_NAME=$(echo $IMAGE_NAME | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Create and push manifest
shell: bash
run: |
# Create manifest list and add the images
for tag in ${{ needs.setup.outputs.tags }}; do
docker manifest create $tag \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:amd64-${{ github.sha }} \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:arm64-${{ github.sha }}
# Annotate the manifest with architecture information
docker manifest annotate $tag \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:amd64-${{ github.sha }} --arch amd64
docker manifest annotate $tag \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:arm64-${{ github.sha }} --arch arm64
# Push the manifest
docker manifest push $tag
done