Skip to content

Commit

Permalink
feat: cache for docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
rutkowski-tomasz committed May 29, 2024
1 parent be2854e commit e6d586e
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 167 deletions.
88 changes: 88 additions & 0 deletions .github/workflows/build-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Reusable Docker Build and Push

on:
workflow_call:
inputs:
cod2_patch:
type: string
description: 'CoD2 patch to use (0=1.0, 3=1.3)'
required: true
mysql_variant:
type: string
description: 'MySQL variant to use (0=disabled, 1=normal, 2=voron)'
required: true
enable_speex:
type: string
required: true
enable_unsafe:
type: string
required: true
enable_push:
type: string
required: true
libcod_commit:
type: string
description: 'Commit hash of libcod to use'
required: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Construct Tag
run: |
tag="rutkowski/cod2:$(cat __version__)-server1.${{ inputs.cod2_patch }}"
if [[ "${{ inputs.mysql_variant }}" == "1" ]]; then
tag="${tag}-mysql"
elif [[ "${{ inputs.mysql_variant }}" == "2" ]]; then
tag="${tag}-mysqlvoron"
fi
if [[ "${{ inputs.enable_speex }}" == "1" ]]; then
tag="${tag}-speex"
fi
if [[ "${{ inputs.enable_unsafe }}" == "1" ]]; then
tag="${tag}-unsafe"
fi
echo $tag
echo "DOCKER_TAG=${tag}" >> $GITHUB_ENV
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: ${{ inputs.enable_push }}
tags: ${{ env.DOCKER_TAG }}
build-args: |
cod2_patch=${{ inputs.cod2_patch }}
mysql_variant=${{ inputs.mysql_variant }}
enable_speex=${{ inputs.enable_speex }}
enable_unsafe=${{ inputs.enable_unsafe }}
libcod_commit=${{ inputs.libcod_commit }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new

- name: Move Docker cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
44 changes: 11 additions & 33 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,15 @@
name: Build and push docker image
name: Build docker image

on: push

jobs:
build:
strategy:
matrix:
cod2_patch: [3]
mysql_variant: [2]
speex: [1]
enable_unsafe: [1]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build all images and push
run: |
PUSH_VALUE=0
if [[ "${{ github.ref }}" == "refs/heads/master" ]]; then
PUSH_VALUE=1
fi
./scripts/build.sh \
--image_name=rutkowski/cod2 \
--cod2_patch=${{ matrix.cod2_patch }} \
--mysql_variant=${{ matrix.mysql_variant }} \
--speex=${{ matrix.speex }} \
--enable_unsafe=${{ matrix.enable_unsafe }} \
--push=$PUSH_VALUE
call-reusable-workflow:
uses: ./.github/workflows/build-push.yml
with:
cod2_patch: 3
mysql_variant: 2
enable_speex: 1
enable_unsafe: 1
enable_push: 0
libcod_commit: "5f04a7f4e60d910945f13a786d15081843b72baf"
secrets: inherit
28 changes: 10 additions & 18 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,17 @@ jobs:
matrix:
cod2_patch: [3]
mysql_variant: [1, 2]
speex: [0, 1]
enable_speex: [0, 1]
enable_unsafe: [0, 1]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Login to DockerHub
uses: docker/login-action@v1
- name: Call Reusable Workflow
uses: ./.github/workflows/docker-build-push.yml
secrets: inherit
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build all images and push
run: |
./scripts/build.sh \
--image_name=rutkowski/cod2 \
--cod2_patch=${{ matrix.cod2_patch }} \
--mysql_variant=${{ matrix.mysql_variant }} \
--speex=${{ matrix.speex }} \
--enable_unsafe=${{ matrix.enable_unsafe }} \
--push=1
cod2_patch: ${{ matrix.cod2_patch }}
mysql_variant: ${{ matrix.mysql_variant }}
enable_speex: ${{ matrix.enable_speex }}
enable_unsafe: ${{ matrix.enable_unsafe }}
enable_push: true
libcod_commit: "5f04a7f4e60d910945f13a786d15081843b72baf"
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ RUN apt-get install -y \
>/dev/null

# speex requirements
ARG speex="0"
RUN if [ "$speex" = "1" ]; then \
ARG enable_speex="0"
RUN if [ "$enable_speex" = "1" ]; then \
apt-get install -y \
git \
libtool \
Expand All @@ -39,7 +39,7 @@ RUN apt-get install -y \
RUN apt-get clean >/dev/null

# compile speex
RUN if [ "$speex" = "1" ]; then \
RUN if [ "$enable_speex" = "1" ]; then \
git clone https://gitlab.xiph.org/xiph/speex.git && \
cd speex && \
git checkout tags/Speex-1.1.9 -b 1.1.9 && \
Expand Down Expand Up @@ -68,7 +68,7 @@ COPY ./doit.sh doit.sh
ARG cod2_patch="0"
ARG mysql_variant="1"
ARG enable_unsafe="0"
RUN ./doit.sh --cod2_patch=${cod2_patch} --speex=${speex} --mysql_variant=${mysql_variant} --enable_unsafe=${enable_unsafe}
RUN ./doit.sh --cod2_patch=${cod2_patch} --enable_speex=${enable_speex} --mysql_variant=${mysql_variant} --enable_unsafe=${enable_unsafe}

RUN mkdir /cod2

Expand Down
10 changes: 4 additions & 6 deletions doit.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/bin/bash

# ./doit.sh --cod2_patch=3 --speex=0 --mysql_variant=2

cc="g++"
options="-I. -m32 -fPIC -Wall"
# -g -ggdb -O0 // debug build without optimization
Expand All @@ -14,8 +12,8 @@ while [ $# -gt 0 ]; do
--cod2_patch=*)
cod2_patch="${1#*=}"
;;
--speex=*)
speex="${1#*=}"
--enalbe_speex=*)
enalbe_speex="${1#*=}"
;;
--mysql_variant=*)
mysql_variant="${1#*=}"
Expand All @@ -34,7 +32,7 @@ while [ $# -gt 0 ]; do
shift
done

for arg_name in "cod2_patch" "speex" "mysql_variant" "enable_unsafe"; do
for arg_name in "cod2_patch" "enalbe_speex" "mysql_variant" "enable_unsafe"; do
arg_value=$(eval echo \$$arg_name)
if [ -z "$arg_value" ]; then
echo "Error: Missing argument --${arg_name}"
Expand Down Expand Up @@ -67,7 +65,7 @@ if [ "$enable_unsafe" == "1" ]; then
sed -i "/#define ENABLE_UNSAFE 0/c\#define ENABLE_UNSAFE 1" config.hpp
fi

if [ "$speex" == "0" ]; then
if [ "$enalbe_speex" == "0" ]; then
speex_link=""
sed -i "/#define COMPILE_CUSTOM_VOICE 1/c\#define COMPILE_CUSTOM_VOICE 0" config.hpp
else
Expand Down
73 changes: 0 additions & 73 deletions scripts/build.sh

This file was deleted.

33 changes: 0 additions & 33 deletions scripts/build_all.sh

This file was deleted.

0 comments on commit e6d586e

Please sign in to comment.