Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unified dockerfile that supports multi arch #2599

Merged
merged 6 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading