Skip to content

Commit

Permalink
Docker Imagepublish (#306)
Browse files Browse the repository at this point in the history
Dockerfile rewrite + GitHub workflow

---------

Co-authored-by: Devis Lucato <[email protected]>
Co-authored-by: Devis Lucato <[email protected]>
  • Loading branch information
3 people authored Feb 15, 2024
1 parent d60c3ef commit c92eaa6
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 1 deletion.
14 changes: 14 additions & 0 deletions .dockerignore
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
31 changes: 31 additions & 0 deletions .github/workflows/image-build-push.yml
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,15 @@ FodyWeavers.xsd

.env
certs/

# to make sure we don't commit local settings which might contain credentials
launchSettings.json
*launchSettings.json*
config.development.yaml
*.development.config
*.development.json
appsettings.*.json

.DS_Store
.idea/
node_modules/
Expand Down
61 changes: 61 additions & 0 deletions Dockerfile
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"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ docker run -it --rm -e OPENAI_API_KEY="..." kernelmemory/service
```

If you prefer using custom settings and services such as Azure OpenAI, Azure
Document Intelligence, etc., you should create an `appsettings.development.json`
Document Intelligence, etc., you should create an `appsettings.Development.json`
file overriding the default values set in `appsettings.json`, or using the
configuration wizard included:

Expand Down

0 comments on commit c92eaa6

Please sign in to comment.