From 3ee91290c74da5a9cc25b06b777d31fb4a79b7fd Mon Sep 17 00:00:00 2001 From: Trung Le Date: Wed, 30 Aug 2023 09:42:48 +0700 Subject: [PATCH 01/11] feat: add dockerfile --- Dockerfile | 22 ++++++++++++++++++++++ docker/appsettings.json | 4 ++++ 2 files changed, 26 insertions(+) create mode 100644 Dockerfile create mode 100644 docker/appsettings.json diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c4ee632 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base + +ARG BB_RUNNER_VERSION=0.4.9 + +WORKDIR /app + +RUN apt-get update && \ + apt-get install --no-install-recommends -y \ + wget unzip && \ + rm -rf /var/lib/apt/lists/* + +RUN wget -q https://github.com/BattleBit-Community-Servers/BattleBitAPIRunner/releases/download/${BB_RUNNER_VERSION}/${BB_RUNNER_VERSION}.zip -O /tmp/runner.zip && \ + unzip -q /tmp/runner.zip -d /app && \ + rm /tmp/runner.zip + +FROM mcr.microsoft.com/dotnet/runtime:6.0 AS app + +WORKDIR /app +COPY --from=base /app /app +COPY docker/appsettings.json /app/appsettings.json + +CMD ["dotnet", "BattleBitAPIRunner.dll"] \ No newline at end of file diff --git a/docker/appsettings.json b/docker/appsettings.json new file mode 100644 index 0000000..70cbb63 --- /dev/null +++ b/docker/appsettings.json @@ -0,0 +1,4 @@ +{ + "IP": "0.0.0.0", + "Port": 29999 +} \ No newline at end of file From a743cbc6729c5fdcea644000d1851903471fc7b1 Mon Sep 17 00:00:00 2001 From: Trung Le Date: Wed, 30 Aug 2023 15:29:19 +0700 Subject: [PATCH 02/11] feat: add docker build workflow --- .github/workflows/build-docker-img.yml | 45 ++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/build-docker-img.yml diff --git a/.github/workflows/build-docker-img.yml b/.github/workflows/build-docker-img.yml new file mode 100644 index 0000000..b97439f --- /dev/null +++ b/.github/workflows/build-docker-img.yml @@ -0,0 +1,45 @@ +name: Build Docker Image + +on: + workflow_dispatch: + push: + branches: + - "main" + paths: + - "docker/**" + - "Dockerfile" + +jobs: + build-docker-img: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + # - name: Login to DockerHub + # uses: docker/login-action@v2 + # with: + # username: ${{ secrets.DOCKERHUB_USERNAME }} + # password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v4 + with: + context: . + platforms: linux/amd64 + push: true + tags: | + ghcr.io/${{ github.repository_owner }}/battlebit-api-runner:latest From c7eaf5419c8254d7557e33a89079b87c1b5bc976 Mon Sep 17 00:00:00 2001 From: Trung Le Date: Wed, 30 Aug 2023 15:30:02 +0700 Subject: [PATCH 03/11] fix: missing workflow trigger --- .github/workflows/build-docker-img.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-docker-img.yml b/.github/workflows/build-docker-img.yml index b97439f..d8510c7 100644 --- a/.github/workflows/build-docker-img.yml +++ b/.github/workflows/build-docker-img.yml @@ -8,6 +8,7 @@ on: paths: - "docker/**" - "Dockerfile" + - ".github/workflows/build-docker-img.yml" jobs: build-docker-img: From cb5d3e5ca80a6a958af75a2a0dfcb87711ea6374 Mon Sep 17 00:00:00 2001 From: Trung Le Date: Wed, 30 Aug 2023 16:21:48 +0700 Subject: [PATCH 04/11] feat: change default ip to localhost --- docker/appsettings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/appsettings.json b/docker/appsettings.json index 70cbb63..d9a98d2 100644 --- a/docker/appsettings.json +++ b/docker/appsettings.json @@ -1,4 +1,4 @@ { - "IP": "0.0.0.0", + "IP": "127.0.0.1", "Port": 29999 } \ No newline at end of file From 626b7f3abcd64bb7439f21b2b141ee4943e79410 Mon Sep 17 00:00:00 2001 From: Trung Le Date: Wed, 30 Aug 2023 20:54:34 +0700 Subject: [PATCH 05/11] feat: rootless user, better data structure --- Dockerfile | 15 +++++++++++++-- docker/appsettings.json | 7 +++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index c4ee632..f00aea3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,8 +15,19 @@ RUN wget -q https://github.com/BattleBit-Community-Servers/BattleBitAPIRunner/re FROM mcr.microsoft.com/dotnet/runtime:6.0 AS app +ARG UNAME=bbr +ARG UID=1000 +ARG GID=1000 + +RUN groupadd -g $GID -o $UNAME \ + && useradd -l -u $UID -g $GID -o -s /bin/bash $UNAME + WORKDIR /app -COPY --from=base /app /app -COPY docker/appsettings.json /app/appsettings.json +COPY --from=base --chown=$UID:$GID /app /app +COPY --chown=$UID:$GID docker/appsettings.json /app/appsettings.json +RUN mkdir -p data/modules data/dependencies data/configurations\ + && chown -R $UID:$GID /app + +USER $UID:$GID CMD ["dotnet", "BattleBitAPIRunner.dll"] \ No newline at end of file diff --git a/docker/appsettings.json b/docker/appsettings.json index d9a98d2..9e35905 100644 --- a/docker/appsettings.json +++ b/docker/appsettings.json @@ -1,4 +1,7 @@ { - "IP": "127.0.0.1", - "Port": 29999 + "IP": "0.0.0.0", + "Port": 29999, + "ModulesPath": "./data/modules", + "DependencyPath": "./data/dependencies", + "ConfigurationPath": "./data/configurations" } \ No newline at end of file From 656c380f7a91d2ca1e29225d247ab53eb494be4b Mon Sep 17 00:00:00 2001 From: Trung Le Date: Wed, 30 Aug 2023 21:09:08 +0700 Subject: [PATCH 06/11] feat: update docker img to 0.4.10 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index f00aea3..e27fbb2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base -ARG BB_RUNNER_VERSION=0.4.9 +ARG BB_RUNNER_VERSION=0.4.10 WORKDIR /app From d61eb484caf0ef3eb872b3516fa859389e7db6b4 Mon Sep 17 00:00:00 2001 From: Trung Le Date: Wed, 30 Aug 2023 21:14:19 +0700 Subject: [PATCH 07/11] feat: docker img support arm64 --- .github/workflows/build-docker-img.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-docker-img.yml b/.github/workflows/build-docker-img.yml index d8510c7..a8c0581 100644 --- a/.github/workflows/build-docker-img.yml +++ b/.github/workflows/build-docker-img.yml @@ -40,7 +40,7 @@ jobs: uses: docker/build-push-action@v4 with: context: . - platforms: linux/amd64 + platforms: linux/amd64,linux/arm64 push: true tags: | ghcr.io/${{ github.repository_owner }}/battlebit-api-runner:latest From 67c452ca92ce188b0a6e15be20746e668223f303 Mon Sep 17 00:00:00 2001 From: Trung Le Date: Wed, 30 Aug 2023 21:31:59 +0700 Subject: [PATCH 08/11] feat: add volume --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index e27fbb2..7647c6c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,4 +30,6 @@ RUN mkdir -p data/modules data/dependencies data/configurations\ USER $UID:$GID +VOLUME ["/app/data"] + CMD ["dotnet", "BattleBitAPIRunner.dll"] \ No newline at end of file From 2abeca64b1670044eba77d8adba6a765dbddc793 Mon Sep 17 00:00:00 2001 From: Trung Le Date: Wed, 30 Aug 2023 21:52:23 +0700 Subject: [PATCH 09/11] feat: tag docker image --- .github/workflows/build-docker-img.yml | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-docker-img.yml b/.github/workflows/build-docker-img.yml index a8c0581..2d5688f 100644 --- a/.github/workflows/build-docker-img.yml +++ b/.github/workflows/build-docker-img.yml @@ -5,10 +5,8 @@ on: push: branches: - "main" - paths: - - "docker/**" - - "Dockerfile" - - ".github/workflows/build-docker-img.yml" + tags: + - "*" jobs: build-docker-img: @@ -36,11 +34,20 @@ jobs: username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{ github.repository_owner }}/battlebit-api-runner + tags: | + type=ref,event=tag + type=ref,event=branch + - name: Build and push uses: docker/build-push-action@v4 with: context: . platforms: linux/amd64,linux/arm64 push: true - tags: | - ghcr.io/${{ github.repository_owner }}/battlebit-api-runner:latest + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} From b3193ca67027ecf72da650ff979a748f95607e40 Mon Sep 17 00:00:00 2001 From: Trung Le Date: Wed, 30 Aug 2023 22:32:24 +0700 Subject: [PATCH 10/11] feat: docker build from source --- .dockerignore | 284 ++++++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 17 ++- 2 files changed, 290 insertions(+), 11 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2270372 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,284 @@ +# Created by https://www.gitignore.io/api/csharp + +### Csharp ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ +Properties/launchSettings.json + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/ +tools/Cake.CoreCLR +.vscode +tools +.dotnet +Dockerfile + +# .env file contains default environment variables for docker +.env +.git/ diff --git a/Dockerfile b/Dockerfile index 7647c6c..b0f828e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,12 @@ -FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base - -ARG BB_RUNNER_VERSION=0.4.10 +FROM mcr.microsoft.com/dotnet/sdk:6.0 AS base WORKDIR /app -RUN apt-get update && \ - apt-get install --no-install-recommends -y \ - wget unzip && \ - rm -rf /var/lib/apt/lists/* +COPY . . -RUN wget -q https://github.com/BattleBit-Community-Servers/BattleBitAPIRunner/releases/download/${BB_RUNNER_VERSION}/${BB_RUNNER_VERSION}.zip -O /tmp/runner.zip && \ - unzip -q /tmp/runner.zip -d /app && \ - rm /tmp/runner.zip +RUN dotnet publish -c Release --output ./bld/ BattleBitAPIRunner.sln \ + && mkdir -p /build/ \ + && cp -r ./bld/* /build/ FROM mcr.microsoft.com/dotnet/runtime:6.0 AS app @@ -23,7 +18,7 @@ RUN groupadd -g $GID -o $UNAME \ && useradd -l -u $UID -g $GID -o -s /bin/bash $UNAME WORKDIR /app -COPY --from=base --chown=$UID:$GID /app /app +COPY --from=base --chown=$UID:$GID /build /app COPY --chown=$UID:$GID docker/appsettings.json /app/appsettings.json RUN mkdir -p data/modules data/dependencies data/configurations\ && chown -R $UID:$GID /app From e9bfa18607e1af9b5f4874a83fe9e0b492f4689b Mon Sep 17 00:00:00 2001 From: Trung Le Date: Wed, 30 Aug 2023 22:43:00 +0700 Subject: [PATCH 11/11] refactor: simplify build path --- Dockerfile | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index b0f828e..fe93bec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,11 @@ +# Base image FROM mcr.microsoft.com/dotnet/sdk:6.0 AS base WORKDIR /app - COPY . . +RUN dotnet publish -c Release --output ./bld/ BattleBitAPIRunner.sln -RUN dotnet publish -c Release --output ./bld/ BattleBitAPIRunner.sln \ - && mkdir -p /build/ \ - && cp -r ./bld/* /build/ - +# App image FROM mcr.microsoft.com/dotnet/runtime:6.0 AS app ARG UNAME=bbr @@ -18,7 +16,7 @@ RUN groupadd -g $GID -o $UNAME \ && useradd -l -u $UID -g $GID -o -s /bin/bash $UNAME WORKDIR /app -COPY --from=base --chown=$UID:$GID /build /app +COPY --from=base --chown=$UID:$GID /app/bld /app COPY --chown=$UID:$GID docker/appsettings.json /app/appsettings.json RUN mkdir -p data/modules data/dependencies data/configurations\ && chown -R $UID:$GID /app