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

Dockerfile update for multi-arch building. #10

Merged
merged 2 commits into from
Sep 4, 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
112 changes: 56 additions & 56 deletions .github/workflows/ghcr-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,58 @@ env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

#jobs:
# build-and-push-image:
# runs-on: ubuntu-latest
#
# permissions:
# contents: read
# packages: write
# attestations: write
# id-token: write
#
# steps:
# - name: Checkout repository
# uses: actions/checkout@v4
#
# - name: Log in to the Container registry
# uses: docker/login-action@v3
# with:
# registry: ${{ env.REGISTRY }}
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
#
# - name: Extract metadata (tags, labels) for Docker
# id: meta
# uses: docker/metadata-action@v5
# with:
# labels: |
# org.opencontainers.image.title=fhir-candle
# org.opencontainers.image.description=A small in-memory FHIR server that can be used for testing and development - NOT for production workloads.
# images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# tags: |
# type=raw,value=latest,enable={{is_default_branch}}
#
# - name: Build and push Docker image
# id: push
# uses: docker/build-push-action@v6
# with:
# context: .
# push: true
# tags: ${{ steps.meta.outputs.tags }}
# labels: ${{ steps.meta.outputs.labels }}
#
# - name: Generate artifact attestation
# uses: actions/attest-build-provenance@v1
# with:
# subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
# subject-digest: ${{ steps.push.outputs.digest }}
# push-to-registry: true

jobs:
build-and-push-image:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}

permissions:
contents: read
Expand All @@ -23,6 +72,12 @@ jobs:
id-token: write

steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Checkout repository
uses: actions/checkout@v4

Expand All @@ -49,6 +104,7 @@ jobs:
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand All @@ -59,59 +115,3 @@ jobs:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true

# jobs:
# build-and-push-image:
# runs-on: ubuntu-latest
# if: ${{ github.event.workflow_run.conclusion == 'success' }}

# permissions:
# contents: read
# packages: write
# attestations: write
# id-token: write

# steps:
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v3

# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3

# - name: Checkout repository
# uses: actions/checkout@v4

# - name: Log in to the Container registry
# uses: docker/login-action@v3
# with:
# registry: ${{ env.REGISTRY }}
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}

# - name: Extract metadata (tags, labels) for Docker
# id: meta
# uses: docker/metadata-action@v5
# with:
# labels: |
# org.opencontainers.image.title=fhir-candle
# org.opencontainers.image.description=A small in-memory FHIR server that can be used for testing and development - NOT for production workloads.
# images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# tags: |
# type=raw,value=latest,enable={{is_default_branch}}

# - name: Build and push Docker image
# id: push
# uses: docker/build-push-action@v6
# with:
# context: .
# platforms: linux/amd64,linux/arm64
# push: true
# tags: ${{ steps.meta.outputs.tags }}
# labels: ${{ steps.meta.outputs.labels }}

# - name: Generate artifact attestation
# uses: actions/attest-build-provenance@v1
# with:
# subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
# subject-digest: ${{ steps.push.outputs.digest }}
# push-to-registry: true
39 changes: 3 additions & 36 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env
ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETARCH
Expand All @@ -9,43 +9,10 @@ WORKDIR /app
COPY . ./

RUN dotnet restore -a $TARGETARCH src/fhir-candle/fhir-candle.csproj
#RUN dotnet build -a $TARGETARCH src/fhir-candle/fhir-candle.csproj -c Release -o out
RUN dotnet publish -a $TARGETARCH src/fhir-candle/fhir-candle.csproj -c Release -o out

#
## Build with platform-specific .Net RID
#RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
#dotnet restore src/fhir-candle/fhir-candle.csproj --arch x64; \
#dotnet publish src/fhir-candle/fhir-candle.csproj -c Release -o out --framework net8.0 --arch x64; \
#elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
#dotnet restore src/fhir-candle/fhir-candle.csproj --arch arm64; \
#dotnet publish src/fhir-candle/fhir-candle.csproj -c Release -o out --framework net8.0 --arch arm64; \
#elif [ "$TARGETPLATFORM" = "windows/x64" ]; then \
#dotnet restore src/fhir-candle/fhir-candle.csproj --arch x64; \
#dotnet publish src/fhir-candle/fhir-candle.csproj -c Release -o out --framework net8.0 --arch x64; \
#elif [ "$TARGETPLATFORM" = "windows/arm64" ]; then \
#dotnet restore src/fhir-candle/fhir-candle.csproj --arch arm64; \
#dotnet publish src/fhir-candle/fhir-candle.csproj -c Release -o out --framework net8.0 --arch arm64; \
#elif [ "$TARGETPLATFORM" = "darwin/x64" ]; then \
#dotnet restore src/fhir-candle/fhir-candle.csproj --arch x64; \
#dotnet publish src/fhir-candle/fhir-candle.csproj -c Release -o out --framework net8.0 --arch x64; \
#elif [ "$TARGETPLATFORM" = "darwin/arm64" ]; then \
#dotnet restore src/fhir-candle/fhir-candle.csproj --arch arm64; \
#dotnet publish src/fhir-candle/fhir-candle.csproj -c Release -o out --framework net8.0 --arch arm64; \
#else \
##echo "Unsupported architecture: $TARGETPLATFORM"; \
##exit 1; \
#dotnet restore src/fhir-candle/fhir-candle.csproj; \
#dotnet publish src/fhir-candle/fhir-candle.csproj -c Release -o out --framework net8.0; \
#fi;

#RUN dotnet publish src/fhir-candle/fhir-candle.csproj -c Release -o out --framework net8.0;
#RUN dotnet restore src/fhir-candle/fhir-candle.csproj
#RUN dotnet publish src/fhir-candle/fhir-candle.csproj -c Release -o out

RUN dotnet publish -a $TARGETARCH src/fhir-candle/fhir-candle.csproj -c Release -o out --no-restore

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:8.0
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "fhir-candle.dll"]
Expand Down
Loading