Skip to content

Commit

Permalink
Automate “latest” docker tag creation (#985)
Browse files Browse the repository at this point in the history
  • Loading branch information
dluc authored Jan 20, 2025
1 parent 068d347 commit 32f5a59
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 120 deletions.
34 changes: 0 additions & 34 deletions .github/workflows/docker-amd64.yml

This file was deleted.

52 changes: 0 additions & 52 deletions .github/workflows/docker-arm64.yml

This file was deleted.

27 changes: 27 additions & 0 deletions .github/workflows/docker-multiarch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,30 @@ jobs:
--build-arg BUILD_IMAGE_TAG=9.0-noble-amd64 \
--build-arg RUN_IMAGE_TAG=9.0-alpine-amd64 \
--tag "${{ vars.DOCKERHUB_USERNAME }}/service:${{ github.event.inputs.docker_tag }}-amd64" .
latest:
runs-on: ubuntu-latest
needs:
- arm64
- amd64
steps:

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Create multi-arch manifest for "latest" tag
run: |
docker pull --platform linux/amd64 "kernelmemory/service:${{ github.event.inputs.docker_tag }}-amd64"
docker pull --platform linux/arm64 "kernelmemory/service:${{ github.event.inputs.docker_tag }}-arm64"
docker manifest create kernelmemory/service:latest \
"kernelmemory/service:${{ github.event.inputs.docker_tag }}-amd64" \
"kernelmemory/service:${{ github.event.inputs.docker_tag }}-arm64"
docker manifest annotate kernelmemory/service:latest "kernelmemory/service:${{ github.event.inputs.docker_tag }}-amd64" --os linux --arch amd64
docker manifest annotate kernelmemory/service:latest "kernelmemory/service:${{ github.event.inputs.docker_tag }}-arm64" --os linux --arch arm64
docker manifest push kernelmemory/service:latest
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Usage: docker buildx build --platform linux/amd64 .
# Usage: docker buildx build --platform linux/arm64 .
# Usage: docker build --platform linux/amd64 --build-arg BUILD_IMAGE_TAG=9.0-noble-amd64 \
# --build-arg RUN_IMAGE_TAG=9.0-alpine-amd64 .
#
# Usage: docker build --platform linux/arm64 --build-arg BUILD_IMAGE_TAG=9.0-noble-arm64v8 \
# --build-arg RUN_IMAGE_TAG=9.0-alpine-arm64v8 .

# See https://github.com/dotnet/dotnet-docker/blob/main/README.sdk.md#full-tag-listing
ARG BUILD_IMAGE_TAG="8.0-jammy"
ARG RUN_IMAGE_TAG="8.0-alpine"
ARG BUILD_IMAGE_TAG="9.0-noble"
ARG RUN_IMAGE_TAG="9.0-alpine"

#########################################################################
# .NET build
Expand Down
2 changes: 0 additions & 2 deletions KernelMemory.sln
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
.github\workflows\dotnet-unit-tests.yml = .github\workflows\dotnet-unit-tests.yml
.github\workflows\github-pages-jekyll.yml = .github\workflows\github-pages-jekyll.yml
.github\workflows\spell-check-with-typos.yml = .github\workflows\spell-check-with-typos.yml
.github\workflows\docker-amd64.yml = .github\workflows\docker-amd64.yml
.github\workflows\docker-arm64.yml = .github\workflows\docker-arm64.yml
.github\workflows\fortify.yml = .github\workflows\fortify.yml
.github\workflows\securitycodescan.yml = .github\workflows\securitycodescan.yml
.github\workflows\docker-multiarch.yml = .github\workflows\docker-multiarch.yml
Expand Down
15 changes: 2 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ Kernel Memory

[![License: MIT](https://img.shields.io/github/license/microsoft/kernel-memory)](https://github.com/microsoft/kernel-memory/blob/main/LICENSE)
[![Discord](https://img.shields.io/discord/1063152441819942922?label=Discord&color=d82679&logo=discord&logoColor=white)](https://aka.ms/KMdiscord)
[![Docker Image Version](https://img.shields.io/docker/v/kernelmemory/service/latest?arch=amd64&label=Docker&color=%230db7ed&logo=docker&logoColor=white)](https://hub.docker.com/r/kernelmemory/service)
[![Docker Image Version](https://img.shields.io/docker/v/kernelmemory/service/latest-arm64?arch=arm64&label=Docker+ARM&color=%230db7ed&logo=docker&logoColor=white)](https://hub.docker.com/r/kernelmemory/service)
[![Docker Image](https://img.shields.io/docker/pulls/kernelmemory/service?label=Docker&color=%230db7ed&logo=docker&logoColor=white)](https://hub.docker.com/r/kernelmemory/service)
[![NuGet Version](https://img.shields.io/nuget/v/Microsoft.KernelMemory?label=nuget&color=%23512BD4&logo=.net&logoColor=white)](https://www.nuget.org/packages/Microsoft.KernelMemory)
[![GitHub Release](https://img.shields.io/github/v/release/microsoft/kernel-memory?color=%23dddddd&label=tag&logo=github&logoColor=white)](https://github.com/microsoft/kernel-memory/releases)

Expand Down Expand Up @@ -276,12 +275,6 @@ to **start the Kernel Memory Service** using OpenAI:
docker run -e OPENAI_API_KEY="..." -it --rm -p 9001:9001 kernelmemory/service
```
on Linux ARM/MacOS use a different tag:
```shell
docker run -e OPENAI_API_KEY="..." -it --rm -p 9001:9001 kernelmemory/service:latest-arm64
```
If you prefer using custom settings and services such as Azure OpenAI, Azure
Document Intelligence, etc., you should create an `appsettings.Development.json`
file overriding the default values set in `appsettings.json`, or using the
Expand All @@ -297,14 +290,10 @@ on Windows:
docker run --volume .\appsettings.Development.json:/app/appsettings.Production.json -it --rm -p 9001:9001 kernelmemory/service
on Linux (AMD64):
on Linux / macOS:
docker run --volume ./appsettings.Development.json:/app/appsettings.Production.json -it --rm -p 9001:9001 kernelmemory/service
on ARM64 / macOS:
docker run --volume ./appsettings.Development.json:/app/appsettings.Production.json -it --rm -p 9001:9001 kernelmemory/service:latest-arm64
🔗 See also:
* [How to configure KM service](https://github.com/microsoft/kernel-memory/blob/main/service/Service/README.md#%EF%B8%8F-configuration)
* [Deploy Kernel Memory to Azure](#kernel-memory-service-on-azure).
Expand Down
2 changes: 0 additions & 2 deletions examples/303-dotnet-aspire/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ internal static void Main()
// RunFromDockerWithOpenAI(s_openAIConfig.APIKey);

// RunFromDockerImage("latest");

// RunFromDockerImage("latest-arm64");
}

private static void RunFromCode()
Expand Down
25 changes: 19 additions & 6 deletions tools/dev/dockerize-amd64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,27 @@ cd "$HERE/../.."

USR=kernelmemory
IMG=${USR}/service
ARCH=amd64

# Prompt user for VERSION
read -p "Enter VERSION (e.g. '0.99.260214.1'): " VERSION
if [ -z "$1" ]; then
# Get the latest git tag and remove any prefix
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
SUGGESTED_VERSION=${LATEST_TAG#*-}
read -p "Enter VERSION (default: '${SUGGESTED_VERSION}'): " VERSION
VERSION=${VERSION:-$SUGGESTED_VERSION}
else
VERSION=$1
read -p "VERSION is set to '${VERSION}'. Press Enter to keep or provide a new value: " NEW_VERSION
VERSION=${NEW_VERSION:-$VERSION}
fi

# Trim VERSION value
VERSION=$(echo "$VERSION" | xargs)

# Ensure VERSION ends with arch name
if [[ "${VERSION:(-6)}" != "-amd64" ]]; then
VERSION="${VERSION}-amd64"
if [[ "${VERSION:(-6)}" != "-${ARCH}" ]]; then
VERSION="${VERSION}-${ARCH}"
fi

# Remove images if they exist
Expand All @@ -37,11 +51,10 @@ for TAG in "${VERSION}" "latest"; do
done

# See https://github.com/dotnet/dotnet-docker/blob/main/README.sdk.md#full-tag-listing
docker buildx build --no-cache --load \
--platform=linux/amd64 \
docker build --platform linux/amd64 \
--build-arg BUILD_IMAGE_TAG=9.0-noble-amd64 \
--build-arg RUN_IMAGE_TAG=9.0-alpine-amd64 \
-t "${IMG}:${VERSION}" \
--push -t "${IMG}:${VERSION}" \
.

# Push images to Docker registry
Expand Down
25 changes: 19 additions & 6 deletions tools/dev/dockerize-arm64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,27 @@ cd "$HERE/../.."

USR=kernelmemory
IMG=${USR}/service
ARCH=arm64

# Prompt user for VERSION
read -p "Enter VERSION (e.g. '0.99.260214.1'): " VERSION
if [ -z "$1" ]; then
# Get the latest git tag and remove any prefix
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
SUGGESTED_VERSION=${LATEST_TAG#*-}
read -p "Enter VERSION (default: '${SUGGESTED_VERSION}'): " VERSION
VERSION=${VERSION:-$SUGGESTED_VERSION}
else
VERSION=$1
read -p "VERSION is set to '${VERSION}'. Press Enter to keep or provide a new value: " NEW_VERSION
VERSION=${NEW_VERSION:-$VERSION}
fi

# Trim VERSION value
VERSION=$(echo "$VERSION" | xargs)

# Ensure VERSION ends with arch name
if [[ "${VERSION:(-6)}" != "-arm64" ]]; then
VERSION="${VERSION}-arm64"
if [[ "${VERSION:(-6)}" != "-${ARCH}" ]]; then
VERSION="${VERSION}-${ARCH}"
fi

# Remove images if they exist
Expand All @@ -37,11 +51,10 @@ for TAG in "${VERSION}" "latest"; do
done

# See https://github.com/dotnet/dotnet-docker/blob/main/README.sdk.md#full-tag-listing
docker buildx build --no-cache --load \
--platform=linux/arm64 \
docker build --platform linux/arm64 \
--build-arg BUILD_IMAGE_TAG=9.0-noble-arm64v8 \
--build-arg RUN_IMAGE_TAG=9.0-alpine-arm64v8 \
-t "${IMG}:${VERSION}" \
--push -t "${IMG}:${VERSION}" \
.

# Push images to Docker registry
Expand Down
23 changes: 22 additions & 1 deletion tools/dev/dockerize-multiarch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,20 @@ USR=kernelmemory
IMG=${USR}/service

# Prompt user for VERSION
read -p "Enter VERSION (e.g. '0.99.260214.1'): " VERSION
if [ -z "$1" ]; then
# Get the latest git tag and remove any prefix
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
SUGGESTED_VERSION=${LATEST_TAG#*-}
read -p "Enter VERSION (default: '${SUGGESTED_VERSION}'): " VERSION
VERSION=${VERSION:-$SUGGESTED_VERSION}
else
VERSION=$1
read -p "VERSION is set to '${VERSION}'. Press Enter to keep or provide a new value: " NEW_VERSION
VERSION=${NEW_VERSION:-$VERSION}
fi

# Trim VERSION value
VERSION=$(echo "$VERSION" | xargs)

# Remove local images if they exist
for TAG in "latest" "${VERSION}-amd64" "${VERSION}-arm64"; do
Expand All @@ -32,21 +45,29 @@ for TAG in "latest" "${VERSION}-amd64" "${VERSION}-arm64"; do
done

# Pull images
echo "# Pulling images..."
docker pull --platform linux/amd64 "kernelmemory/service:${VERSION}-amd64"
docker pull --platform linux/arm64 "kernelmemory/service:${VERSION}-arm64"

# Delete manifest
echo "# Deleting manifest..."
docker manifest rm kernelmemory/service:latest || true

# Create manifest
echo "# Creating new manifest..."
docker manifest create kernelmemory/service:latest \
"kernelmemory/service:${VERSION}-amd64" \
"kernelmemory/service:${VERSION}-arm64"

# Add images to manifest
echo "# Adding images to new manifest..."
docker manifest annotate kernelmemory/service:latest \
"kernelmemory/service:${VERSION}-amd64" --os linux --arch amd64
docker manifest annotate kernelmemory/service:latest \
"kernelmemory/service:${VERSION}-arm64" --os linux --arch arm64

# Publish manifest
echo "# Publishing manifest..."
docker manifest push kernelmemory/service:latest


Expand Down

0 comments on commit 32f5a59

Please sign in to comment.