Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add GitHub Actions for container build and push #48

Merged
merged 5 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.DS_Store
.git
.github
.gitignore
.private
.vs
.vscode
*.csv
*.json
**/obj
**/bin
artifacts
docker
docker-compose.yml
justfile
Dockerfile
41 changes: 41 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Configuration options see: https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "docker"
directories:
- "/"
schedule:
interval: "daily"
labels:
- "dependencies"
reviewers:
- "Fenrikur"
- "Metawolve"
- "Rain336"
- package-ecosystem: "nuget"
directories:
- "/"
schedule:
interval: "daily"
labels:
- "dependencies"
reviewers:
- "Fenrikur"
- "Metawolve"
- "Rain336"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
day: "sunday"
time: "16:00"
groups:
all-actions:
patterns: [ "*" ]
labels:
- "dependencies"
reviewers:
- "Fenrikur"
- "Metawolve"
- "Rain336"
41 changes: 41 additions & 0 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Create and publish container image

on:
push:
branches:
- 'main'
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'

jobs:
call_build-and-push-image_nightly:
if: startsWith(github.ref, 'refs/heads/')
permissions:
contents: read
packages: write
uses: eurofurence/reg-workflows/.github/workflows/docker-build-push.yml@main
with:
image-name: ${{ github.repository }}
image-tags: nightly
full-repo-url: https://github.com/${{ github.repository }}
branch-or-tag-name: ${{ github.ref_name }}
commit-hash: ${{ github.sha }}
registry-user: ${{ github.actor }}
secrets:
registry-pass: ${{ secrets.GITHUB_TOKEN }}

call_build-and-push-image_release:
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: read
packages: write
uses: eurofurence/reg-workflows/.github/workflows/docker-build-push.yml@main
with:
image-name: ${{ github.repository }}
image-tags: ${{ github.ref_name }} latest
full-repo-url: https://github.com/${{ github.repository }}
branch-or-tag-name: ${{ github.ref_name }}
commit-hash: ${{ github.sha }}
registry-user: ${{ github.actor }}
secrets:
registry-pass: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,6 @@ paket-files/
*.sln.iml

docker/

# Local user files
.private
23 changes: 12 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env
COPY ./src /app/src
COPY ./test /app/test
COPY ./ef-app_backend-dotnet-core.sln /app
COPY ./appsettings.json /app
COPY ./firebase.json /app
COPY ./NuGet.config /app
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
COPY . /app/
WORKDIR /app
RUN ["dotnet", "restore"]
RUN dotnet build src/Eurofurence.App.Server.Web/Eurofurence.App.Server.Web.csproj --configuration Release
RUN dotnet publish src/Eurofurence.App.Tools.CliToolBox/Eurofurence.App.Tools.CliToolBox.csproj --output "$(pwd)/artifacts" --configuration Release
RUN dotnet publish src/Eurofurence.App.Server.Web/Eurofurence.App.Server.Web.csproj --output "$(pwd)/artifacts" --configuration Release
RUN dotnet restore \
&& dotnet build src/Eurofurence.App.Server.Web/Eurofurence.App.Server.Web.csproj --configuration Release \
&& dotnet publish src/Eurofurence.App.Tools.CliToolBox/Eurofurence.App.Tools.CliToolBox.csproj --output "/app/artifacts" --configuration Release \
&& dotnet publish src/Eurofurence.App.Server.Web/Eurofurence.App.Server.Web.csproj --output "/app/artifacts" --configuration Release
ENTRYPOINT dotnet artifacts/Eurofurence.App.Server.Web.dll http://*:30001
EXPOSE 30001

FROM mcr.microsoft.com/dotnet/aspnet:8.0-jammy-chiseled
COPY --from=build /app/artifacts/* /app/
WORKDIR /app
ENTRYPOINT ["dotnet", "Eurofurence.App.Server.Web.dll", "http://*:30001"]
EXPOSE 30001
68 changes: 0 additions & 68 deletions appsettings.example.json

This file was deleted.

33 changes: 23 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
version: '2'
version: '3.1'
services:
api:
build: .
backend:
image: ghcr.io/eurofurence/ef-app_backend-dotnet-core:dev
build:
context: .
dockerfile: Dockerfile
ports:
- "30001:30001"
- '30001:30001'
volumes:
- './appsettings.json:/app/appsettings.json'
- './firebase.json:/app/firebase.json'
depends_on:
- "database"
database:
image: mongo
db:
condition: service_healthy
db:
image: docker.io/mariadb:latest
environment:
MARIADB_DATABASE: 'ef_backend'
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: 1
volumes:
- './docker/mongo:/data/db'
ports:
- '27017:27017'
- db:/var/lib/mysql
healthcheck:
test: mariadb-admin ping -h 127.0.0.1 -u root
start_period: 5s
interval: 5s
timeout: 5s
retries: 30
volumes:
db:
52 changes: 52 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# List available recipes
default:
just --list

# Create file with given name and extension from NAME.sample.EXTENSION in PROJECT
_create_from_sample PROJECT NAME EXTENSION:
if [ ! -f "{{NAME}}.{{EXTENSION}}" ]; then cp "src/{{PROJECT}}/{{NAME}}.sample.{{EXTENSION}}" "{{NAME}}.{{EXTENSION}}"; fi

# Start the docker compose stack
up *ARGS: (_create_from_sample "Eurofurence.App.Server.Web" "appsettings" "json") (_create_from_sample "Eurofurence.App.Server.Web" "firebase" "json")
docker-compose up {{ARGS}}

# Bring the docker compose stack down and remove volumes
down:
docker-compose down -v --remove-orphans

# Stop the docker compose stack
stop:
docker-compose stop

# Clean build, stack, container images and artifacts
clean:
dotnet clean
rm -rf artifacts build
find . -type d -name "bin" -print0 | xargs -0 rm -rf
find . -type d -name "obj" -print0 | xargs -0 rm -rf
docker-compose down || true
docker rmi ghcr.io/eurofurence/ef-app_backend-dotnet-core:dev-sdk || true
docker rmi ghcr.io/eurofurence/ef-app_backend-dotnet-core:dev || true

# Perform restore, build & publish with dotnet
build:
dotnet restore
dotnet build src/Eurofurence.App.Server.Web/Eurofurence.App.Server.Web.csproj --configuration Release
dotnet publish src/Eurofurence.App.Tools.CliToolBox/Eurofurence.App.Tools.CliToolBox.csproj --output "$(pwd)/artifacts" --configuration Release
dotnet publish src/Eurofurence.App.Server.Web/Eurofurence.App.Server.Web.csproj --output "$(pwd)/artifacts" --configuration Release

# Build just CLI tools as single, self-contained executable
build-cli:
dotnet publish src/Eurofurence.App.Tools.CliToolBox/Eurofurence.App.Tools.CliToolBox.csproj --output "$(pwd)/artifacts" --configuration Release --sc -p:PublishSingleFile=true -p:DebugType=None -p:DebugSymbols=false -p:GenerateDocumentationFile=false

# Build release container using spec from docker-compose.yml
containerize:
docker-compose build

# Build sdk container without executing second stage
containerize-dev:
docker build --target build -t ghcr.io/eurofurence/ef-app_backend-dotnet-core:dev-sdk -f Dockerfile .

# Open swagger UI in default browser
swagger:
open http://127.0.0.1:30001/swagger/ui/index.html
15 changes: 9 additions & 6 deletions src/Eurofurence.App.Server.Web/appsettings.sample.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"ConnectionStrings": {
"Eurofurence": "Server=127.0.0.1; Port=3306; Database=ef_backend; user=root; SslMode=Preferred;"
},
"global": {
"conventionNumber": 23,
"conventionIdentifier": "EF25",
"conventionNumber": 99,
"conventionIdentifier": "EFXX",
"regSysAuthenticationEnabled": 0,
"baseUrl": "",
"appIdITunes": 0,
"appIdPlay": ""
},
"logLevel": 1,
"auditLog": "/tmp/audit.log",
"ConnectionStrings": {
"Eurofurence": "Server=db; Port=3306; Database=ef_backend; user=root; SslMode=Preferred;"
},
"oAuth": {
"issuer": "EurofurenceAppWebApi",
"audience": "EurofurenceAppWebApi",
Expand All @@ -23,7 +23,10 @@
"targetTopic": "Debug"
},
"firebase": {
"googleServiceCredentialKeyFile": "/tmp/service-credentials.json",
"googleServiceCredentialKeyFile": "firebase.json",
"topics": [
"EFXX"
],
"expo": {
"scopeKey": "@eurofurence/ef-app-react-native",
"experienceId": "@eurofurence/ef-app-react-native"
Expand Down
12 changes: 12 additions & 0 deletions src/Eurofurence.App.Server.Web/firebase.sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "service_account",
"project_id": "<custom>",
"private_key_id": "<custom>",
"private_key": "<custom>",
"client_email": "<custom>",
"client_id": "<custom>",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/<custom>.iam.gserviceaccount.com"
}