Skip to content

Commit

Permalink
Merge pull request #2599 from hriprsd/development
Browse files Browse the repository at this point in the history
unified dockerfile that supports multi arch
  • Loading branch information
moreal authored Oct 17, 2024
2 parents 0178216 + 2d793dc commit 1c74e28
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/push_docker_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@ jobs:
docker build . \
-f ${{ matrix.docker.dockerfile }}.amd64 \
-t ${{ matrix.docker.repo }}:git-${{ github.sha }}-amd64 \
--build-arg COMMIT=git-${{ github.sha }}
--build-arg COMMIT=git-${{ github.sha }} \
--build-arg TARGETPLATFORM=linux/amd64
docker push ${{ matrix.docker.repo }}:git-${{ github.sha }}-amd64
- name: build-and-push-arm64v8
run: |
docker build . \
-f ${{ matrix.docker.dockerfile }}.arm64v8 \
-t ${{ matrix.docker.repo }}:git-${{ github.sha }}-arm64v8 \
--build-arg COMMIT=git-${{ github.sha }}
--build-arg COMMIT=git-${{ github.sha }} \
--build-arg TARGETPLATFORM=linux/arm64
docker push ${{ matrix.docker.repo }}:git-${{ github.sha }}-arm64v8
- name: merge-manifest-and-push
run: |
Expand Down
28 changes: 23 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0-jammy AS build-env
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env
WORKDIR /app
ARG COMMIT
ARG TARGETPLATFORM

# Copy csproj and restore as distinct layers
COPY ./Lib9c/Lib9c/Lib9c.csproj ./Lib9c/
Expand All @@ -16,23 +17,40 @@ RUN dotnet restore NineChronicles.Headless.Executable

# Copy everything else and build
COPY . ./
RUN dotnet publish NineChronicles.Headless.Executable/NineChronicles.Headless.Executable.csproj \
RUN <<EOF
#!/bin/bash
echo "TARGETPLATFROM=$TARGETPLATFORM"
if [[ "$TARGETPLATFORM" = "linux/amd64" ]]
then
dotnet publish NineChronicles.Headless.Executable/NineChronicles.Headless.Executable.csproj \
-c Release \
-r linux-x64 \
-o out \
--self-contained \
--version-suffix $COMMIT
elif [[ "$TARGETPLATFORM" = "linux/arm64" ]]
then
dotnet publish NineChronicles.Headless.Executable/NineChronicles.Headless.Executable.csproj \
-c Release \
-r linux-arm64 \
-o out \
--self-contained \
--version-suffix $COMMIT
else
echo "Not supported target platform: '$TARGETPLATFORM'."
exit -1
fi
EOF

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:8.0
FROM --platform=$TARGETPLATFORM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
RUN apt-get update && apt-get install -y libc6-dev
COPY --from=build-env /app/out .

# Install native deps & utilities for production
RUN apt-get update \
&& apt-get install -y --allow-unauthenticated \
libc6-dev jq curl \
libc6-dev liblz4-dev zlib1g-dev libsnappy-dev libzstd-dev jq curl \
&& rm -rf /var/lib/apt/lists/*

VOLUME /data
Expand Down
23 changes: 21 additions & 2 deletions Dockerfile.ACC
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0-jammy AS build-env
WORKDIR /app
ARG COMMIT
ARG TARGETPLATFORM

# Copy csproj and restore as distinct layers
COPY ./Lib9c/Lib9c/Lib9c.csproj ./Lib9c/
Expand All @@ -13,15 +14,33 @@ RUN dotnet restore NineChronicles.Headless.AccessControlCenter

# Copy everything else and build
COPY . ./
RUN dotnet publish NineChronicles.Headless.AccessControlCenter/NineChronicles.Headless.AccessControlCenter.csproj \
RUN <<EOF
#!/bin/bash
echo "TARGETPLATFROM=$TARGETPLATFORM"
if [[ "$TARGETPLATFORM" = "linux/amd64" ]]
then
dotnet publish NineChronicles.Headless.AccessControlCenter/NineChronicles.Headless.AccessControlCenter.csproj \
-c Release \
-r linux-x64 \
-o out \
--self-contained \
--version-suffix $COMMIT
elif [[ "$TARGETPLATFORM" = "linux/arm64" ]]
then
dotnet publish NineChronicles.Headless.AccessControlCenter/NineChronicles.Headless.AccessControlCenter.csproj \
-c Release \
-r linux-arm64 \
-o out \
--self-contained \
--version-suffix $COMMIT
else
echo "Not supported target platform: '$TARGETPLATFORM'."
exit -1
fi
EOF

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:8.0
FROM --platform=$TARGETPLATFORM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
RUN apt-get update && apt-get install -y libc6-dev
COPY --from=build-env /app/out .
Expand Down

0 comments on commit 1c74e28

Please sign in to comment.