Skip to content

Commit

Permalink
improve: clean and update docker (#716)
Browse files Browse the repository at this point in the history
Docker was not working very well, so I made a cleanup and update the Dockerfile and also the startup script to work with the current code.

Also made some improvements to the script that docker uses to start canary.
  • Loading branch information
Costallat authored Jan 12, 2023
1 parent d1ac9a7 commit ccb2474
Show file tree
Hide file tree
Showing 13 changed files with 275 additions and 451 deletions.
58 changes: 44 additions & 14 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- main

jobs:
docker:
build_docker_x86:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -27,20 +27,20 @@ jobs:
uses: gittools/actions/gitversion/execute@v0.9.15

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2.1.0
uses: docker/setup-buildx-action@v2
with:
install: true

- name: Cache Docker layers
uses: actions/cache@main
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
key: ${{ runner.os }}-x86-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
${{ runner.os }}-x86-
- name: Login to GitHub Container Registry
uses: docker/login-action@v2.1.0
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
Expand All @@ -50,7 +50,7 @@ jobs:
if: ${{ github.event_name == 'pull_request' }}
uses: docker/build-push-action@v3.2.0
with:
file: docker/server/Dockerfile
file: docker/Dockerfile.x86
tags: ghcr.io/${{ github.repository }}:${{ steps.gitversion.outputs.semVer }}
cache-from: type=gha, scope=${{ github.workflow }}
cache-to: type=gha, scope=${{ github.workflow }}
Expand All @@ -60,7 +60,7 @@ jobs:
if: ${{ github.event_name == 'push' }}
uses: docker/build-push-action@v3.2.0
with:
file: docker/server/Dockerfile
file: docker/Dockerfile.x86
push: true
tags: ghcr.io/${{ github.repository }}:${{ steps.gitversion.outputs.semVer }}
cache-from: type=gha, scope=${{ github.workflow }}
Expand All @@ -70,10 +70,40 @@ jobs:
if: ${{ github.event_name == 'push' }}
run: echo ${{ steps.docker_build.outputs.digest }}

# # Temp fix
# # https://github.com/docker/build-push-action/issues/252
# # https://github.com/moby/buildkit/issues/1896
# - name: Move cache
# run: |
# rm -rf /tmp/.buildx-cache
# mv /tmp/.buildx-cache-new /tmp/.buildx-cache
build_docker_arm:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@main
with:
fetch-depth: 0

- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0.9.15
with:
versionSpec: '5.x'

- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/execute@v0.9.15

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
install: true

- name: Cache Docker layers
uses: actions/cache@main
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-arm-${{ github.sha }}
restore-keys: |
${{ runner.os }}-arm-
- name: Build
uses: docker/build-push-action@v3.2.0
with:
file: docker/Dockerfile.arm
tags: ghcr.io/${{ github.repository }}:${{ steps.gitversion.outputs.semVer }}
cache-from: type=gha, scope=${{ github.workflow }}
cache-to: type=gha, scope=${{ github.workflow }}
1 change: 0 additions & 1 deletion docker/.gitignore

This file was deleted.

49 changes: 49 additions & 0 deletions docker/Dockerfile.arm
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Stage 1: Download all dependencies
FROM ubuntu:22.04 AS dependencies

RUN apt-get update && apt-get install -y --no-install-recommends cmake git \
unzip build-essential ca-certificates curl zip unzip tar \
pkg-config ninja-build autoconf automake libtool libluajit-5.1-dev libluajit-5.1-common \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /opt
RUN git clone https://github.com/microsoft/vcpkg --depth=1 \
&& ./vcpkg/bootstrap-vcpkg.sh

WORKDIR /opt/vcpkg
COPY vcpkg.json /opt/vcpkg/
RUN VCPKG_FORCE_SYSTEM_BINARIES=1 /opt/vcpkg/vcpkg --feature-flags=binarycaching,manifests,versions install

# Stage 2: create build
FROM dependencies AS build

COPY . /srv/
WORKDIR /srv

RUN export VCPKG_ROOT=/opt/vcpkg/ && VCPKG_FORCE_SYSTEM_BINARIES=1 cmake --preset linux-release && cmake --build --preset linux-release

# Stage 3: load data and execute
FROM ubuntu:22.04

VOLUME [ "/data" ]

COPY --from=build /srv/build/linux-release/bin/canary /bin/canary
COPY LICENSE *.sql key.pem /canary/
COPY data /canary/data
COPY data-canary /canary/data-canary
COPY data-otservbr-global /canary/data-otservbr-global
COPY config.lua.dist /canary/config.lua

WORKDIR /canary

RUN apt-get update && apt-get install -y --no-install-recommends \
mariadb-client libluajit-5.1-dev libluajit-5.1-common wget curl \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

COPY docker/data/01-test_account.sql 01-test_account.sql
COPY docker/data/02-test_account_players.sql 02-test_account_players.sql
COPY docker/data/start.sh start.sh

ENTRYPOINT ["/canary/start.sh"]
13 changes: 9 additions & 4 deletions docker/server/Dockerfile → docker/Dockerfile.x86
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends cmake git \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /opt
RUN git clone https://github.com/microsoft/vcpkg --depth=1
RUN ./vcpkg/bootstrap-vcpkg.sh
RUN git clone https://github.com/microsoft/vcpkg --depth=1 \
&& ./vcpkg/bootstrap-vcpkg.sh

WORKDIR /opt/vcpkg
COPY vcpkg.json /opt/vcpkg/
Expand All @@ -25,19 +25,24 @@ RUN export VCPKG_ROOT=/opt/vcpkg/ && cmake --preset linux-release && cmake --bui

# Stage 3: load data and execute
FROM ubuntu:22.04
VOLUME [ "/data" ]

COPY --from=build /srv/build/linux-release/bin/canary /bin/canary
COPY LICENSE *.sql key.pem /canary/
COPY data /canary/data
COPY data-canary /canary/data-canary
COPY data-otservbr-global /canary/data-otservbr-global
COPY config.lua.dist /canary/config.lua

WORKDIR /canary

RUN apt-get update && apt-get install -y --no-install-recommends \
mariadb-client \
mariadb-client curl \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

COPY docker/server/start.sh start.sh
COPY docker/data/01-test_account.sql 01-test_account.sql
COPY docker/data/02-test_account_players.sql 02-test_account_players.sql
COPY docker/data/start.sh start.sh

ENTRYPOINT ["/canary/start.sh"]
13 changes: 0 additions & 13 deletions docker/data/download-myaac.sh

This file was deleted.

183 changes: 0 additions & 183 deletions docker/data/login.py

This file was deleted.

Loading

0 comments on commit ccb2474

Please sign in to comment.