diff --git a/.github/workflows/build-push.yml b/.github/workflows/build-push.yml new file mode 100644 index 0000000..9c7e3d5 --- /dev/null +++ b/.github/workflows/build-push.yml @@ -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 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1b3f77d..7fdeed0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d92c514..750903a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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" diff --git a/scripts/build.sh b/scripts/build.sh deleted file mode 100755 index 758bfa2..0000000 --- a/scripts/build.sh +++ /dev/null @@ -1,73 +0,0 @@ -#!/bin/bash -ex - -VERSION=$(cat __version__) - -# [Custom] Get parameters -speex=0 -mysql_variant=0 -enable_unsafe=0 -push=0 - -while [ $# -gt 0 ]; do - case "$1" in - --image_name=*) - image_name="${1#*=}" - ;; - --cod2_patch=*) - cod2_patch="${1#*=}" - ;; - --mysql_variant=*) - mysql_variant="${1#*=}" - ;; - --speex=*) - speex="${1#*=}" - ;; - --enable_unsafe=*) - enable_unsafe="${1#*=}" - ;; - --push=*) - push="${1#*=}" - ;; - *) - echo "Unknown argument: $1" - exit 1 - ;; - esac - shift -done - -for arg_name in "image_name" "cod2_patch"; do - arg_value=$(eval echo \$$arg_name) - if [ -z "$arg_value" ]; then - echo "Error: Missing argument --${arg_name}" - exit 1 - fi -done -# End: [Custom] Get parameters - -tag="${image_name}:${VERSION}-server1.${cod2_patch}" -if [[ "$mysql_variant" -eq 1 ]]; then - tag="${tag}-mysql" -elif [[ "$mysql_variant" -eq 2 ]]; then - tag="${tag}-mysqlvoron" -fi - -if [[ "$speex" -eq 1 ]]; then - tag="${tag}-speex" -fi - -if [[ "$enable_unsafe" -eq 1 ]]; then - tag="${tag}-unsafe" -fi - -docker build \ - --build-arg cod2_patch="${cod2_patch}" \ - --build-arg mysql_variant="${mysql_variant}" \ - --build-arg speex=${speex} \ - --build-arg enable_unsafe=${enable_unsafe} \ - -t $tag \ - . - -if [[ "$push" -eq 1 ]]; then - docker push ${tag} -fi diff --git a/scripts/build_all.sh b/scripts/build_all.sh deleted file mode 100755 index 8681471..0000000 --- a/scripts/build_all.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash -ex - -IMAGE_NAME=${1:-rutkowski/cod2} -PUSH=${2:-""} - -cod_patches=( 0 2 3 ) -mysql_variants=( 1 2 ) -speex_options=( 0 1 ) -enable_unsafe_options=( 0 1 ) - -for cod_patch in "${cod_patches[@]}" -do - for mysql_variant in "${mysql_variants[@]}" - do - for speex in "${speex_options[@]}" - do - for enable_unsafe in "${enable_unsafe_options[@]}" - do - echo "Building and pushing with parameters cod_patch=$cod_patch, mysql_variant=$mysql_variant, speex=$speex, enable_unsafe=$enable_unsafe" - - ./build.sh \ - --image_name=$IMAGE_NAME \ - --cod2_patch=$cod_patch \ - --mysql_variant=$mysql_variant \ - --speex=$speex \ - --enable_unsafe=$enable_unsafe \ - --push=$PUSH - - echo "Done" - done - done - done -done