-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dockerfile rewrite + GitHub workflow --------- Co-authored-by: Devis Lucato <[email protected]> Co-authored-by: Devis Lucato <[email protected]>
- Loading branch information
1 parent
d60c3ef
commit c92eaa6
Showing
5 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.dockerignore | ||
.env | ||
.git | ||
.gitignore | ||
.vs | ||
.vscode | ||
docker-compose.yml | ||
docker-compose.*.yml | ||
*/bin | ||
*/obj | ||
|
||
# To make sure that the local appsettings files are not copied when building the image locally. | ||
# These files are not in GitHub thanks to .gitignore | ||
**/*appsettings.*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Build image and push it to docker hub | ||
|
||
name: Build and Push Docker Image | ||
|
||
on: workflow_dispatch | ||
|
||
jobs: | ||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: Build and push | ||
uses: docker/build-push-action@v5 | ||
with: | ||
push: true | ||
platforms: linux/amd64,linux/arm64 | ||
tags: ${{ secrets.DOCKERHUB_USERNAME }}/service:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
ARG BUILD_IMAGE_TAG="7.0-jammy" | ||
ARG RUN_IMAGE_TAG="7.0-alpine" | ||
|
||
######################################################################### | ||
# build and publish | ||
######################################################################### | ||
|
||
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:$BUILD_IMAGE_TAG AS build | ||
ARG BUILD_CONFIGURATION=Release | ||
|
||
ARG TARGETARCH | ||
ARG TARGETPLATFORM | ||
ARG BUILDPLATFORM | ||
|
||
WORKDIR /src | ||
COPY ["service/Service/Service.csproj", "service/Service/"] | ||
RUN dotnet restore "./service/Service/./Service.csproj" | ||
|
||
COPY ["extensions", "extensions"] | ||
COPY ["tools", "tools"] | ||
COPY ["service", "service"] | ||
WORKDIR "/src/service/Service" | ||
RUN dotnet build "./Service.csproj" -c $BUILD_CONFIGURATION -o /app/build | ||
|
||
FROM build AS publish | ||
ARG BUILD_CONFIGURATION=Release | ||
RUN dotnet publish "./Service.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false | ||
|
||
######################################################################### | ||
# run | ||
######################################################################### | ||
|
||
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/aspnet:$RUN_IMAGE_TAG AS base | ||
# Non-root user that will run the service | ||
ARG USER=km | ||
RUN \ | ||
# Create user | ||
#Debian: useradd --create-home --user-group $USER --shell /bin/bash && \ | ||
adduser -D -h /app -s /bin/sh $USER && \ | ||
# Allow user to access the build | ||
chown -R $USER.$USER /app | ||
|
||
# Define current user | ||
USER $USER | ||
|
||
# Used by .NET and KM to load appsettings.Production.json | ||
ENV ASPNETCORE_ENVIRONMENT Production | ||
ENV ASPNETCORE_URLS http://+:9001 | ||
|
||
WORKDIR /app | ||
EXPOSE 9001 | ||
|
||
FROM base AS final | ||
|
||
MAINTAINER Devis Lucato "https://github.com/dluc" | ||
WORKDIR /app | ||
|
||
COPY --from=publish --chown=km:km --chmod=0550 /app/publish . | ||
|
||
# Define executable | ||
ENTRYPOINT ["dotnet", "Microsoft.KernelMemory.ServiceAssembly.dll"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters