Skip to content

Commit

Permalink
build: Add docker support (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
VMelnalksnis committed Nov 20, 2022
1 parent 6e6a656 commit 0224457
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/bin/*
**/obj/*
**/node_modules/*
**/.github/*
**/.idea/*
17 changes: 17 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,23 @@ jobs:
env:
MOLECULE_DISTRO: ${{ matrix.distro }}

docker:
name: Test docker container
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- run: >
docker build
--tag ghcr.io/vmelnalksnis/gnomeshade:test
--build-arg "BUILD_NUMBER=${{ github.run_number }}"
./
- run: docker run --name test -d -p 8000:80 ghcr.io/vmelnalksnis/gnomeshade:test
- run: wget --tries=10 --retry-connrefused --waitretry=1 --timeout=15 "http://localhost:8000/health"
- run: >
[[ $(cat health) = "Healthy" ]] || exit 1
- run: docker logs test
if: always()

resharper:
name: Resharper
runs-on: ubuntu-latest
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,25 @@ jobs:
--api-key ${{ secrets.NUGET_KEY }}
--source https://api.nuget.org/v3/index.json
docker:
name: Build docker image
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- run: >
docker build
--tag ghcr.io/vmelnalksnis/gnomeshade:nightly
--build-arg "BUILD_NUMBER=${{ github.run_number }}"
./
- run: docker push ghcr.io/vmelnalksnis/gnomeshade:nightly

deploy-demo:
name: Deploy demo app
needs: build-linux
Expand Down
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM mcr.microsoft.com/dotnet/sdk:6.0.403 AS build

RUN apt-get update && apt-get install -y \
npm \
zip

WORKDIR /gnomeshade
COPY ./ ./
ARG BUILD_NUMBER=123
RUN ./deployment/publish.sh "Gnomeshade.WebApi" "linux-musl-x64" $BUILD_NUMBER

RUN ls /gnomeshade/source/Gnomeshade.WebApi/bin/Release/net6.0/linux-musl-x64/publish/ -lah

FROM mcr.microsoft.com/dotnet/runtime-deps:6.0.11-alpine3.16 as gnomeshade

COPY --from=build /gnomeshade/source/Gnomeshade.WebApi/bin/Release/net6.0/linux-musl-x64/publish/Gnomeshade.WebApi /gnomeshade/
COPY --from=build /gnomeshade/source/Gnomeshade.WebApi/bin/Release/net6.0/linux-musl-x64/publish/libe_sqlite3.so /gnomeshade/
COPY --from=build /gnomeshade/source/Gnomeshade.WebApi/bin/Release/net6.0/linux-musl-x64/publish/appsettings.json ./gnomeshade/
COPY --from=build /gnomeshade/source/Gnomeshade.WebApi/bin/Release/net6.0/linux-musl-x64/publish/wwwroot/ /gnomeshade/wwwroot

ENV Database__Provider="Sqlite" \
ConnectionStrings__Gnomeshade="Data Source=/data/gnomeshade.db" \
Jwt__ValidAudience="http://localhost:5000" \
Jwt__ValidIssuer="http://localhost:5000" \
Jwt__Secret="280ba7e4-d323-4232-8107-3b8c1b0832a8"

VOLUME /data
EXPOSE 80
ENTRYPOINT ["/gnomeshade/Gnomeshade.WebApi"]
2 changes: 2 additions & 0 deletions Gnomeshade.sln
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Directory.Packages.props = Directory.Packages.props
global.json = global.json
nuget.config = nuget.config
.dockerignore = .dockerignore
Dockerfile = Dockerfile
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gnomeshade.WebApi.Tests", "tests\Gnomeshade.WebApi.Tests\Gnomeshade.WebApi.Tests.csproj", "{0C052464-F71A-4005-A531-C6D6B4FF09A4}"
Expand Down
25 changes: 16 additions & 9 deletions deployment/publish.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash
version=$(cat version)
#!/bin/sh
set -e

version=$(tr -d '[:space:]' <version)
publish_dir="./source/$1/bin/Release/net6.0/$2/publish"
archive_name="$1_$2.zip"

Expand All @@ -12,14 +14,19 @@ dotnet publish \
--self-contained \
--no-restore \
-p:PublishSingleFile=true \
-p:AssemblyVersion="$version"."$3" \
-p:InformationalVersion="$version""$4"+"$2" \
-p:AssemblyVersion="$version.$3" \
-p:InformationalVersion="$version$4$2" \
/warnAsError \
/nologo

pushd "$publish_dir" || exit
zip -r -9 "$archive_name" .
popd || exit
(
cd "$publish_dir" || exit
zip -r -9 "$archive_name" .
)

echo "artifact-name=$archive_name" >> "$GITHUB_OUTPUT"
echo "artifact=$publish_dir/$archive_name" >> "$GITHUB_OUTPUT"
if [ -z "$GITHUB_OUTPUT" ]; then
echo "Not in GitHub Actions"
else
echo "artifact-name=$archive_name" >>"$GITHUB_OUTPUT"
echo "artifact=$publish_dir/$archive_name" >>"$GITHUB_OUTPUT"
fi
2 changes: 1 addition & 1 deletion deployment/restore.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
set -e

dotnet restore --locked-mode /p:Configuration="Release"

0 comments on commit 0224457

Please sign in to comment.