-
Notifications
You must be signed in to change notification settings - Fork 3
57 lines (49 loc) · 1.92 KB
/
multiplatform_docker_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
name: Multi-Platform Docker Build
on:
workflow_dispatch:
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
# Step 1: Check out the repository and submodules
- name: Check out code
uses: actions/checkout@v3
with:
submodules: true # Fetch submodules
fetch-depth: 0 # Ensure the full history is fetched
# Step 2: Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# Step 3: Install yq
- name: Install yq
run: |
sudo apt-get update && sudo apt-get install -y wget
sudo wget https://github.com/mikefarah/yq/releases/download/v4.35.1/yq_linux_amd64 -O /usr/bin/yq
sudo chmod +x /usr/bin/yq
# Step 4: Extract component-version and component-name from odtp.yml
- name: Extract component-version and component-name
id: extract_info
run: |
VERSION=$(yq e '.component-version' odtp.yml)
NAME=$(yq e '.component-name' odtp.yml)
echo "VERSION=${VERSION}"
echo "NAME=${NAME}"
echo "COMPONENT_VERSION=${VERSION}" >> $GITHUB_ENV
echo "COMPONENT_NAME=${NAME}" >> $GITHUB_ENV
# Step 5: Log in to GitHub Container Registry
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Step 6: Build and push Docker image for multiple platforms
- name: Build and push Docker image
run: |
IMAGE_NAME=ghcr.io/${{ github.repository }}/${{ env.COMPONENT_NAME }}
docker buildx build \
--platform linux/amd64,linux/arm64 \
--build-arg COMPONENT_VERSION=${{ env.COMPONENT_VERSION }} \
-t $IMAGE_NAME:${{ env.COMPONENT_VERSION }} \
-t $IMAGE_NAME:latest \
--push .