-
-
Notifications
You must be signed in to change notification settings - Fork 78
Add Docker support and CI workflow for Docker image publish #459
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
Open
enzofrnt
wants to merge
31
commits into
BeamMP:minor
Choose a base branch
from
enzofrnt:docker-support
base: minor
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 21 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
6e812cb
Add Docker support and CI workflow
enzofrnt 1e0fd1d
Add docker-support branch to workflow triggers
enzofrnt e42b41c
Refactor Docker build and update CI caching
enzofrnt ea917f2
Set IMAGE_NAME dynamically in Docker workflow
enzofrnt 11971a5
Update Docker workflow to set IMAGE_NAME in env
enzofrnt 129751d
Update BeamMP-Server copy path in Dockerfile
enzofrnt 1647e6b
Split Docker build workflow by architecture
enzofrnt f06543d
Refactor Docker workflow to use matrix build
enzofrnt fccea15
Update docker/build-push-action to v6 in workflow
enzofrnt 6fa4a5e
Add Docker build cache configuration to workflow
enzofrnt d182a9b
Disable provenance and SBOM in Docker build
enzofrnt a566097
Clean up Dockerfile comments and update copy note
enzofrnt 44431bc
Update BeamMP server image in compose.yaml
enzofrnt dc4670b
Remove commented configuration from compose.yaml
enzofrnt c9aaee5
Remove 'docker-support' branch from workflow triggers
enzofrnt 554ee51
Fix image name casing in Docker Compose file
enzofrnt 593d05a
Update Docker CMD and resource volume paths
enzofrnt 9c5fbd1
Add .env example and update Docker config
enzofrnt eb87c3d
Improve docker workflow (#1)
enzofrnt c957523
docker: add Lua + LuaRocks support (#2)
enzofrnt 3572255
Remove obsolete branch from Docker workflow
enzofrnt 4edcbc0
Update .env.example with default BeamMP values
enzofrnt e7ab580
Use BEAMMP_PORT env variable for port mapping
enzofrnt 719cfaf
Tidy Docker files, workflow comments, and ignores
enzofrnt e9a549d
Add provider disable flag and remove config mount
enzofrnt 9066648
Remove Resources volume mount from compose.yaml
enzofrnt c117b1b
Document BeamMP Server env link in .env.example
enzofrnt fe93f07
Set BEAMMP_PROVIDER_DISABLE_CONFIG in compose
enzofrnt 8fafe13
Remove default CMD from Dockerfile
enzofrnt 27cf7bf
Revert "Remove Resources volume mount from compose.yaml"
enzofrnt dca9fbd
Remove volume comment in compose.yaml
enzofrnt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| .git/ | ||
| build/ | ||
| cmake-build-*/ | ||
| bin/ | ||
| out/ | ||
| .cache/ | ||
| **/.DS_Store | ||
|
|
||
| # IDE | ||
| .idea/ | ||
| .vs/ | ||
| *.user | ||
| *.suo | ||
|
|
||
| # CI | ||
| .github/ | ||
|
|
||
| # Scripts (pas nécessaires au build Docker ici) | ||
| scripts/ | ||
|
|
||
| # Docs (garde README si tu veux) | ||
| *.md | ||
| !README.md | ||
|
|
||
| # Docker files (garde ce dont tu as besoin) | ||
| docker-compose*.yml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| BEAMMP_DEBUG= | ||
| BEAMMP_PRIVATE= | ||
| BEAMMP_PORT= | ||
| BEAMMP_MAX_CARS= | ||
| BEAMMP_MAX_PLAYERS= | ||
| BEAMMP_MAP= | ||
| BEAMMP_NAME= | ||
| BEAMMP_DESCRIPTION= | ||
| BEAMMP_TAGS= | ||
| BEAMMP_RESOURCE_FOLDER= | ||
| BEAMMP_AUTH_KEY= | ||
| BEAMMP_LOG_CHAT= | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| name: Docker Build and Publish (native multi-arch) | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - 'develop' | ||
| - 'minor' | ||
| tags: | ||
| - 'v*' | ||
| pull_request: | ||
|
|
||
| env: | ||
| REGISTRY: ghcr.io | ||
|
|
||
| jobs: | ||
| build: | ||
| name: Build ${{ matrix.arch }} | ||
| runs-on: ${{ matrix.runner }} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| include: | ||
| - arch: amd64 | ||
| platform: linux/amd64 | ||
| runner: ubuntu-24.04 | ||
| - arch: arm64 | ||
| platform: linux/arm64 | ||
| runner: ubuntu-24.04-arm | ||
|
|
||
| permissions: | ||
| contents: read | ||
| packages: write | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| submodules: recursive | ||
|
|
||
| - name: Set image name (lowercase) | ||
| run: echo "IMAGE_NAME=${GITHUB_REPOSITORY@L}" >> $GITHUB_ENV | ||
|
|
||
| - uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - uses: docker/login-action@v3 | ||
| with: | ||
| registry: ${{ env.REGISTRY }} | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - uses: docker/metadata-action@v5 | ||
| id: meta | ||
| with: | ||
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
| flavor: | | ||
| suffix=-${{ matrix.arch }} | ||
| tags: | | ||
| type=ref,event=branch | ||
| type=ref,event=tag | ||
| type=ref,event=pr | ||
| type=semver,pattern={{version}} | ||
| type=semver,pattern={{major}}.{{minor}} | ||
|
|
||
| - uses: docker/build-push-action@v6 | ||
| with: | ||
| context: . | ||
| platforms: ${{ matrix.platform }} | ||
| push: true | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
| labels: ${{ steps.meta.outputs.labels }} | ||
|
|
||
| cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-${{ matrix.arch }} | ||
| cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-${{ matrix.arch }},mode=max | ||
|
|
||
| provenance: false | ||
| sbom: false | ||
|
|
||
| merge: | ||
| runs-on: ubuntu-24.04 | ||
| needs: [build] | ||
| permissions: | ||
| contents: read | ||
| packages: write | ||
|
|
||
| steps: | ||
| - name: Set image name (lowercase) | ||
| run: echo "IMAGE_NAME=${GITHUB_REPOSITORY@L}" >> $GITHUB_ENV | ||
|
|
||
| - uses: docker/login-action@v3 | ||
| with: | ||
| registry: ${{ env.REGISTRY }} | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - uses: docker/metadata-action@v5 | ||
| id: meta | ||
| with: | ||
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
| tags: | | ||
| type=ref,event=branch | ||
| type=ref,event=tag | ||
| type=ref,event=pr | ||
| type=semver,pattern={{version}} | ||
| type=semver,pattern={{major}}.{{minor}} | ||
|
|
||
| - name: Create multi-arch manifests | ||
| env: | ||
| TAGS: ${{ steps.meta.outputs.tags }} | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| while IFS= read -r tag; do | ||
| [ -n "$tag" ] || continue | ||
|
|
||
| echo "Merging: $tag" | ||
| docker buildx imagetools create \ | ||
| -t "$tag" \ | ||
| "${tag}-amd64" \ | ||
| "${tag}-arm64" | ||
| done <<< "$TAGS" | ||
|
|
||
| - name: Inspect | ||
| run: | | ||
| # Affiche les détails de l'image créée pour vérification | ||
| # On utilise le premier tag de la liste pour l'inspection | ||
| TAG_TO_INSPECT=$(echo "${{ steps.meta.outputs.tags }}" | head -n 1) | ||
| docker buildx imagetools inspect $TAG_TO_INSPECT || true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -478,3 +478,8 @@ callgrind.* | |
| notes/* | ||
| compile_commands.json | ||
| nohup.out | ||
|
|
||
| build/ | ||
|
|
||
| #Ignore Docker env file | ||
| .env | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| FROM debian:12-slim AS builder | ||
|
|
||
| ARG VCPKG_COMMIT=5bf0c55239da398b8c6f450818c9e28d36bf9966 | ||
| ARG BUILD_PARALLEL=2 | ||
| ARG ENABLE_LTO=ON | ||
|
|
||
| ENV DEBIAN_FRONTEND=noninteractive \ | ||
| CMAKE_BUILD_TYPE=Release \ | ||
| VCPKG_FORCE_SYSTEM_BINARIES=1 \ | ||
| VCPKG_FEATURE_FLAGS=manifests | ||
|
|
||
| WORKDIR /work | ||
|
|
||
| RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ | ||
| --mount=type=cache,target=/var/lib/apt,sharing=locked \ | ||
| apt-get update && apt-get install -y --no-install-recommends \ | ||
| ca-certificates \ | ||
| curl \ | ||
| zip unzip tar \ | ||
| git \ | ||
| cmake \ | ||
| ninja-build \ | ||
| build-essential \ | ||
| pkg-config \ | ||
| liblua5.3-0 liblua5.3-dev \ | ||
| binutils \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| RUN git clone https://github.com/microsoft/vcpkg /work/vcpkg && \ | ||
| cd /work/vcpkg && \ | ||
| git checkout ${VCPKG_COMMIT} && \ | ||
| ./bootstrap-vcpkg.sh -disableMetrics | ||
|
|
||
| ENV VCPKG_ROOT=/work/vcpkg | ||
|
|
||
| COPY vcpkg.json ./ | ||
| COPY deps/ ./deps/ | ||
| COPY cmake/ ./cmake/ | ||
| COPY CMakeLists.txt ./ | ||
| COPY include/ ./include/ | ||
| COPY src/ ./src/ | ||
| COPY test/ ./test/ | ||
|
|
||
| RUN --mount=type=cache,target=/root/.cache/vcpkg,sharing=locked \ | ||
| --mount=type=cache,target=/work/vcpkg/downloads,sharing=locked \ | ||
| --mount=type=cache,target=/work/vcpkg/buildtrees,sharing=locked \ | ||
| --mount=type=cache,target=/work/vcpkg/packages,sharing=locked \ | ||
| --mount=type=cache,target=/work/build-server,sharing=locked \ | ||
| mkdir -p /work/out && \ | ||
| cmake -S /work -B /work/build-server -G Ninja \ | ||
| -DCMAKE_TOOLCHAIN_FILE=/work/vcpkg/scripts/buildsystems/vcpkg.cmake \ | ||
| -DCMAKE_BUILD_TYPE=Release \ | ||
| -DCMAKE_EXE_LINKER_FLAGS="-Wl,--export-dynamic" \ | ||
| -DCMAKE_CXX_FLAGS="-O3 -g -Wl,-z,norelro -Wl,--hash-style=gnu -Wl,-z,noseparate-code -ffunction-sections -fdata-sections -Wl,--gc-sections" \ | ||
| -DBeamMP-Server_ENABLE_LTO=${ENABLE_LTO} \ | ||
| && cmake --build /work/build-server --parallel ${BUILD_PARALLEL} -t BeamMP-Server \ | ||
| && objcopy --only-keep-debug /work/build-server/BeamMP-Server /work/build-server/BeamMP-Server.debug \ | ||
| && strip --strip-unneeded /work/build-server/BeamMP-Server \ | ||
| && objcopy --add-gnu-debuglink=/work/build-server/BeamMP-Server.debug /work/build-server/BeamMP-Server \ | ||
| && install -m 0755 /work/build-server/BeamMP-Server /work/out/BeamMP-Server | ||
|
|
||
| RUN --mount=type=cache,target=/root/.cache/vcpkg,sharing=locked \ | ||
| --mount=type=cache,target=/work/vcpkg/downloads,sharing=locked \ | ||
| --mount=type=cache,target=/work/vcpkg/buildtrees,sharing=locked \ | ||
| --mount=type=cache,target=/work/vcpkg/packages,sharing=locked \ | ||
| --mount=type=cache,target=/work/build-tests,sharing=locked \ | ||
| cmake -S /work -B /work/build-tests -G Ninja \ | ||
| -DCMAKE_TOOLCHAIN_FILE=/work/vcpkg/scripts/buildsystems/vcpkg.cmake \ | ||
| -DCMAKE_BUILD_TYPE=Release \ | ||
| -DCMAKE_EXE_LINKER_FLAGS="-Wl,--export-dynamic" \ | ||
| -DBeamMP-Server_ENABLE_LTO=OFF \ | ||
| && cmake --build /work/build-tests --parallel 1 -t BeamMP-Server-tests | ||
|
|
||
| FROM debian:12-slim AS runtime | ||
|
|
||
| RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
| liblua5.3-0 \ | ||
| lua5.3 \ | ||
| luarocks \ | ||
| build-essential \ | ||
| pkg-config \ | ||
| liblua5.3-dev \ | ||
| git \ | ||
| unzip \ | ||
| curl \ | ||
| ca-certificates \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| RUN useradd -m -u 1000 beammp && \ | ||
| mkdir -p /app /app/data /config /resources && \ | ||
| chown -R beammp:beammp /app /config /resources | ||
|
|
||
| # /work/build-server is a BuildKit cache mount (not persisted in layers), so copy from /work/out. | ||
| COPY --from=builder /work/out/BeamMP-Server /app/BeamMP-Server | ||
|
|
||
| WORKDIR /app | ||
| USER beammp | ||
enzofrnt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| EXPOSE 30814 | ||
| ENTRYPOINT ["/app/BeamMP-Server"] | ||
| CMD ["--config=/config/ServerConfig.toml"] | ||
enzofrnt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,38 @@ | ||
| find_package(Git) | ||
| find_package(Git QUIET) | ||
|
|
||
| # Only try to update submodules if: | ||
| # - the option is enabled | ||
| # - git is available | ||
| # - we are in a real git checkout (".git" exists) | ||
| if(${PROJECT_NAME}_CHECKOUT_GIT_SUBMODULES) | ||
| if(Git_FOUND) | ||
| message(STATUS "Git found, submodule update and init") | ||
| execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init | ||
| WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
| RESULT_VARIABLE GIT_SUBMOD_RESULT) | ||
| if(NOT GIT_SUBMOD_RESULT EQUAL "0") | ||
| message(SEND_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules. This may result in missing dependencies.") | ||
| if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") | ||
| message(STATUS "Git found, submodule update and init") | ||
| execute_process( | ||
| COMMAND "${GIT_EXECUTABLE}" submodule update --init --recursive | ||
| WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" | ||
| RESULT_VARIABLE GIT_SUBMOD_RESULT | ||
| ) | ||
| if(NOT GIT_SUBMOD_RESULT EQUAL 0) | ||
| message(SEND_ERROR | ||
| "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules. " | ||
| "This may result in missing dependencies." | ||
| ) | ||
| endif() | ||
| else() | ||
| message(STATUS "No .git directory found - skipping submodule update (assume submodules are already present).") | ||
| endif() | ||
| else() | ||
| message(SEND_ERROR "git required for checking out submodules, but not found. Submodules will not be checked out - this may result in missing dependencies.") | ||
| message(SEND_ERROR | ||
| "git required for checking out submodules, but not found. Submodules will not be checked out - " | ||
| "this may result in missing dependencies." | ||
| ) | ||
| endif() | ||
| endif() | ||
|
|
||
| if(Git_FOUND) | ||
|
|
||
| if(Git_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") | ||
| # If you compute PRJ_GIT_HASH somewhere else, keep that logic there. | ||
| else() | ||
| message(STATUS "Git not found - the version will not include a git hash.") | ||
| message(STATUS "Git not found (or not a git checkout) - the version will not include a git hash.") | ||
| set(PRJ_GIT_HASH "unknown") | ||
| endif() | ||
| endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| services: | ||
| beammp-server: | ||
| build: | ||
| context: . | ||
| dockerfile: Dockerfile | ||
| image: ghcr.io/beammp/beammp-server | ||
| container_name: beammp-server | ||
| restart: unless-stopped | ||
enzofrnt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ports: | ||
| - "30814:30814/tcp" | ||
| - "30814:30814/udp" | ||
enzofrnt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| volumes: | ||
| # Mount configuration directory | ||
| - ./config:/config | ||
| # Mount resources directory (mods, plugins, etc.) | ||
enzofrnt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - ./Resources:/app/Resources | ||
| env_file: | ||
| - .env | ||
| environment: | ||
| - TZ=UTC | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.