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 12808e2
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 157 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/build-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
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)'
mysql_variant:
type: string
description: 'MySQL variant to use (0=disabled, 1=normal, 2=voron)'
enable_speex:
type: boolean
default: false
enable_unsafe:
type: boolean
default: false
enable_push:
type: boolean
default: false
libcod_commit:
type: string
description: 'Commit hash of libcod to use'

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 }}
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
43 changes: 10 additions & 33 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,14 @@
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: true
enable_unsafe: true
push: false
libcod_commit: "5f04a7f4e60d910945f13a786d15081843b72baf"
27 changes: 9 additions & 18 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,16 @@ 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
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 }}
push: true
libcod_commit: "5f04a7f4e60d910945f13a786d15081843b72baf"
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 12808e2

Please sign in to comment.