Skip to content

Commit

Permalink
Build docker container for tags
Browse files Browse the repository at this point in the history
  • Loading branch information
papauorg committed Jul 10, 2024
1 parent f91fbf5 commit 015541d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 21 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**/bin/
**/obj/
**/out/
**/.git
Dockerfile
.github
.vscode
49 changes: 29 additions & 20 deletions .github/workflows/build_and_validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ name: .NET
on:
push:
branches: [ "main" ]
tags:
- '*'
pull_request:
branches: [ "main" ]

Expand All @@ -28,40 +30,47 @@ jobs:
PUBLISH_IMAGE=false
TAGS="$IMAGE_NAME_LOWERCASE:dev"
# Define the image that will be used as a cached image
# to speed up the build process
BUILD_CACHE_IMAGE_NAME=${TAGS}
if [[ ${GITHUB_REF_NAME} == ref/tags/* ]]; then
LATEST_IMAGE=$IMAGE_NAME_LOWERCASE:latest
VERSION=${GITHUB_REF_NAME#ref/tags/}
TAGS="${LATEST_IMAGE},$IMAGE_NAME_LOWERCASE:v${VERSION}"
PUBLISH_IMAGE=true
fi
echo "tags: $TAGS"
echo "publish_image: $PUBLISH_IMAGE"
echo "cache_name: $BUILD_CACHE_IMAGE_NAME"
echo "tags=$TAGS" >> $GITHUB_OUTPUT
echo "publish_image=$PUBLISH_IMAGE" >> $GITHUB_OUTPUT
echo "cache_name=$BUILD_CACHE_IMAGE_NAME" >> $GITHUB_OUTPUT
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- uses: docker/build-push-action@v4
with:
context: .
file: "Dockerfile"
tags: ${{ steps.prep.outputs.tags }}
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
push: false
cache-from: type=registry,ref=${{ steps.prep.outputs.cache_name }}
cache-to: type=inline
push: ${{ steps.prep.outputs.publish_image == 'true' }}
labels: |
org.opencontainers.image.title=${{ github.event.repository.name }}
org.opencontainers.image.description=${{ github.event.repository.description }}
org.opencontainers.image.url=${{ github.event.repository.html_url }}
org.opencontainers.image.revision=${{ github.sha }}
- name: Validate json schemas
uses: addnab/docker-run-action@v3
with:
image: ${{ steps.prep.outputs.tags }}
options: -v ${{ github.workspace }}:/workspaces/levelmeter
run: cd /workspaces/levelmeter && find /workspaces/levelmeter/scales/definitions/*.json | xargs -I % check-jsonschema % --schemafile /workspaces/levelmeter/scales/definitions/schemas/scale-config
- name: Build and test
uses: addnab/docker-run-action@v3
with:
image: ${{ steps.prep.outputs.tags }}
options: -v ${{ github.workspace }}:/workspaces/levelmeter
run: cd /workspaces/levelmeter && dotnet build --configuration=Release && dotnet test --configuration=Release
- name: Test recreating all cylinder definitions
uses: addnab/docker-run-action@v3
with:
image: ${{ steps.prep.outputs.tags }}
options: -v ${{ github.workspace }}:/workspaces/levelmeter
run: cd /workspaces/levelmeter && find /workspaces/levelmeter/scales/definitions/cylinder*.json | xargs -I % dotnet run --project /workspaces/levelmeter/src/dotnet-levelmeter/dotnet-levelmeter.csproj -- -c %
run: |
find ./scales/definitions/cylinder*.json | xargs -I % docker run -v $(pwd):/config $IMAGE_NAME -c %
16 changes: 15 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,18 @@ ENV PATH=$GEM_HOME/bin:$PATH
USER vscode
RUN gem install jekyll bundler

USER root
USER root



FROM dev as build
WORKDIR /build
COPY . .
RUN find ./scales/definitions/*.json | xargs -I % check-jsonschema % --schemafile ./scales/definitions/schemas/scale-config
RUN dotnet build --configuration=Release && dotnet test --no-build --configuration=Release

FROM mcr.microsoft.com/dotnet/runtime:8.0
WORKDIR /app
COPY --from=build /build/src/dotnet-levelmeter/bin/Release/net8.0 .
WORKDIR /config
ENTRYPOINT [ "dotnet", "/app/dotnet-levelmeter.dll", "--"]

0 comments on commit 015541d

Please sign in to comment.