Skip to content

Commit 7a429f3

Browse files
authored
Fixing dockerization for ARM64 (#814)
* Remove multi-arch builds, which are not working correctly on ARM (segmentation fault) * Split github workflow by arch. ARM arch dockerization to be run manually for now, until fixed. * Deprecate "sha" labels to avoid confusion)
1 parent 0d3e6f4 commit 7a429f3

File tree

5 files changed

+152
-27
lines changed

5 files changed

+152
-27
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,17 @@
11
# Build Docker image and push it to docker hub
22

3-
name: Docker Image Build and Push to DockerHub
3+
name: Dockerize amd64
44

55
on: workflow_dispatch
66

77
jobs:
88
build-and-push-image:
99
runs-on: ubuntu-latest
1010
steps:
11+
1112
- name: Checkout code
1213
uses: actions/checkout@v4
1314

14-
- name: Docker meta
15-
id: meta
16-
uses: docker/metadata-action@v5
17-
with:
18-
# list of Docker images to use as base name for tags
19-
images: |
20-
${{ vars.DOCKERHUB_USERNAME }}/service
21-
# Docker tags to generate
22-
tags: |
23-
type=raw,value=latest
24-
type=sha
25-
2615
- name: Set up QEMU
2716
uses: docker/setup-qemu-action@v3
2817

@@ -35,10 +24,26 @@ jobs:
3524
username: ${{ vars.DOCKERHUB_USERNAME }}
3625
password: ${{ secrets.DOCKERHUB_TOKEN }}
3726

27+
- name: Docker meta
28+
id: meta
29+
uses: docker/metadata-action@v5
30+
with:
31+
# list of Docker images to use as base name for tags
32+
images: |
33+
${{ vars.DOCKERHUB_USERNAME }}/service
34+
# Docker tags to generate
35+
tags: |
36+
type=raw,value=latest
37+
3838
- name: Build and push
39-
uses: docker/build-push-action@v5
39+
uses: docker/build-push-action@v6
4040
with:
41+
context: .
4142
push: true
42-
platforms: linux/amd64,linux/arm64
43+
platforms: linux/amd64
44+
# See https://github.com/dotnet/dotnet-docker/blob/main/README.sdk.md#full-tag-listing
45+
build-args: |
46+
BUILD_IMAGE_TAG=8.0-jammy-amd64
47+
RUN_IMAGE_TAG=8.0-alpine-amd64
4348
labels: ${{ steps.meta.outputs.labels }}
4449
tags: ${{ steps.meta.outputs.tags }}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Build Docker image and push it to docker hub
2+
3+
name: Dockerize arm64
4+
5+
on: workflow_dispatch
6+
7+
jobs:
8+
build-and-push-image:
9+
runs-on: macos-latest
10+
steps:
11+
12+
# https://github.com/actions/runner/issues/1456
13+
- name: Setup docker (missing on MacOS)
14+
if: runner.os == 'macos'
15+
run: |
16+
export HOMEBREW_NO_AUTO_UPDATE=1
17+
brew install docker colima
18+
colima start
19+
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Set up QEMU
24+
uses: docker/setup-qemu-action@v3
25+
26+
- name: Set up Docker Buildx
27+
uses: docker/setup-buildx-action@v3
28+
29+
- name: Login to Docker Hub
30+
uses: docker/login-action@v3
31+
with:
32+
username: ${{ vars.DOCKERHUB_USERNAME }}
33+
password: ${{ secrets.DOCKERHUB_TOKEN }}
34+
35+
- name: Docker meta
36+
id: meta
37+
uses: docker/metadata-action@v5
38+
with:
39+
# list of Docker images to use as base name for tags
40+
images: |
41+
${{ vars.DOCKERHUB_USERNAME }}/service
42+
# Docker tags to generate
43+
tags: |
44+
type=raw,value=latest-arm64
45+
46+
- name: Build and push
47+
uses: docker/build-push-action@v6
48+
with:
49+
context: .
50+
push: true
51+
platforms: linux/arm64
52+
# See https://github.com/dotnet/dotnet-docker/blob/main/README.sdk.md#full-tag-listing
53+
build-args: |
54+
BUILD_IMAGE_TAG=8.0-jammy-arm64v8
55+
RUN_IMAGE_TAG=8.0-alpine-arm64v8
56+
labels: ${{ steps.meta.outputs.labels }}
57+
tags: ${{ steps.meta.outputs.tags }}

Dockerfile

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
1-
# Usage: docker buildx build .
1+
# Usage: docker buildx build --platform linux/amd64 .
2+
# Usage: docker buildx build --platform linux/arm64 .
23

4+
# See https://github.com/dotnet/dotnet-docker/blob/main/README.sdk.md#full-tag-listing
35
ARG BUILD_IMAGE_TAG="8.0-jammy"
46
ARG RUN_IMAGE_TAG="8.0-alpine"
57

6-
ARG PLATFORM=$BUILDPLATFORM
7-
#ARG PLATFORM=$TARGETPLATFORM
8-
98
#########################################################################
109
# .NET build
1110
#########################################################################
1211

13-
# ARG BUILDPLATFORM
14-
FROM --platform=$PLATFORM mcr.microsoft.com/dotnet/sdk:$BUILD_IMAGE_TAG AS build
12+
FROM mcr.microsoft.com/dotnet/sdk:$BUILD_IMAGE_TAG AS build
1513

1614
ARG BUILD_CONFIGURATION=Release
1715

1816
COPY . /src/
1917
WORKDIR "/src/service/Service"
18+
2019
RUN dotnet build Service.csproj -c $BUILD_CONFIGURATION -o /app/build /p:RepoRoot=/src/
2120
RUN dotnet publish "./Service.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false /p:RepoRoot=/src/
2221

2322
#########################################################################
2423
# prepare final content
2524
#########################################################################
2625

27-
ARG PLATFORM
28-
FROM --platform=$PLATFORM mcr.microsoft.com/dotnet/aspnet:$RUN_IMAGE_TAG AS base
26+
FROM mcr.microsoft.com/dotnet/aspnet:$RUN_IMAGE_TAG AS base
2927

3028
# Non-root user that will run the service
3129
ARG USER=km
@@ -46,15 +44,14 @@ COPY --from=build --chown=km:km --chmod=0550 /app/publish .
4644
#########################################################################
4745

4846
LABEL org.opencontainers.image.authors="Devis Lucato, https://github.com/dluc"
49-
MAINTAINER Devis Lucato "https://github.com/dluc"
5047

5148
# Define current user
5249
USER $USER
5350

5451
# Used by .NET and KM to load appsettings.Production.json
55-
ENV ASPNETCORE_ENVIRONMENT Production
56-
ENV ASPNETCORE_URLS http://+:9001
57-
ENV ASPNETCORE_HTTP_PORTS 9001
52+
ENV ASPNETCORE_ENVIRONMENT=Production
53+
ENV ASPNETCORE_URLS=http://+:9001
54+
ENV ASPNETCORE_HTTP_PORTS=9001
5855

5956
EXPOSE 9001
6057

tools/dockerize-amd64.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/"
6+
cd "$HERE"
7+
8+
USR=kernelmemory
9+
IMG=${USR}/service
10+
TAG=:latest
11+
12+
set +e
13+
docker rmi ${IMG}${TAG} >/dev/null 2>&1
14+
set -e
15+
16+
if [ -z "$(docker images -q ${IMG}${TAG})" ]; then
17+
echo "All ${IMG}${TAG} images have been deleted."
18+
else
19+
echo "Some ${IMG}${TAG} images are still present:"
20+
docker images ${IMG}${TAG}
21+
exit -1
22+
fi
23+
24+
# See https://github.com/dotnet/dotnet-docker/blob/main/README.sdk.md#full-tag-listing
25+
docker buildx build --no-cache --load \
26+
--platform=linux/amd64 \
27+
--build-arg BUILD_IMAGE_TAG=8.0-jammy-amd64 \
28+
--build-arg RUN_IMAGE_TAG=8.0-alpine-amd64 \
29+
-t ${IMG}${TAG} .
30+
31+
docker login -u ${USR} --password-stdin
32+
33+
docker push ${IMG}${TAG}

tools/dockerize-arm64.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/"
6+
cd "$HERE"
7+
8+
USR=kernelmemory
9+
IMG=${USR}/service
10+
TAG=:latest-arm64
11+
12+
set +e
13+
docker rmi ${IMG}${TAG} >/dev/null 2>&1
14+
set -e
15+
16+
if [ -z "$(docker images -q ${IMG}${TAG})" ]; then
17+
echo "All ${IMG}${TAG} images have been deleted."
18+
else
19+
echo "Some ${IMG}${TAG} images are still present:"
20+
docker images ${IMG}${TAG}
21+
exit -1
22+
fi
23+
24+
# See https://github.com/dotnet/dotnet-docker/blob/main/README.sdk.md#full-tag-listing
25+
docker buildx build --no-cache --load \
26+
--platform=linux/arm64 \
27+
--build-arg BUILD_IMAGE_TAG=8.0-jammy-arm64v8 \
28+
--build-arg RUN_IMAGE_TAG=8.0-alpine-arm64v8 \
29+
-t ${IMG}${TAG} .
30+
31+
docker login -u ${USR} --password-stdin
32+
33+
docker push ${IMG}${TAG}

0 commit comments

Comments
 (0)