Docker Publish #60
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
| name: Docker Publish | |
| on: | |
| workflow_dispatch: | |
| push: | |
| paths: | |
| - "generate-dockerfiles.sh" | |
| - "generate-docker-compose.sh" | |
| - "requirements.txt" | |
| - "Dockerfile.j2" | |
| - "docker-compose.yml.j2" | |
| schedule: | |
| - cron: "0 3 * * 6" | |
| concurrency: | |
| group: docker-publish-${{ github.ref }} | |
| cancel-in-progress: false | |
| jobs: | |
| generate-dockerfiles: | |
| name: Generate Dockerfiles | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| outputs: | |
| matrix: ${{ steps.set-matrix.outputs.matrix }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - name: Generate python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.12" | |
| cache: "pip" | |
| cache-dependency-path: requirements.txt | |
| - run: pip3 install -r requirements.txt | |
| - name: Generate Dockerfile with generate-dockerfiles.sh | |
| run: ./generate-dockerfiles.sh | |
| - name: Upload a Build Artifact | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| # Artifact name | |
| name: Dockerfiles | |
| # A file, directory or wildcard pattern that describes what to upload | |
| path: dockerfiles | |
| - name: Commit and push generated Dockerfiles | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add dockerfiles/Dockerfile* | |
| if git diff --cached --quiet; then | |
| echo "No Dockerfile changes to commit" | |
| exit 0 | |
| fi | |
| git commit -m "Generate Dockerfiles" | |
| git pull --rebase origin "${GITHUB_REF_NAME}" | |
| git push origin "HEAD:${GITHUB_REF_NAME}" | |
| - id: set-matrix | |
| run: | | |
| shortnamearray=$(cat "shortnamearray.json") | |
| echo "${shortnamearray}" | |
| echo -n "matrix=${shortnamearray}" >> "${GITHUB_OUTPUT}" | |
| generate-docker-compose: | |
| name: Generate docker-compose.yml files | |
| runs-on: ubuntu-latest | |
| needs: generate-dockerfiles | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - name: Setup python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.12" | |
| cache: "pip" | |
| cache-dependency-path: requirements.txt | |
| - run: pip3 install -r requirements.txt | |
| - name: Generate docker-compose.yml files with generate-docker-compose.sh | |
| run: ./generate-docker-compose.sh | |
| - name: Commit and push generated docker-compose files | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add docker-compose/docker-compose* | |
| if git diff --cached --quiet; then | |
| echo "No docker-compose changes to commit" | |
| exit 0 | |
| fi | |
| git commit -m "Generate docker-compose.yml files" | |
| git pull --rebase origin "${GITHUB_REF_NAME}" | |
| git push origin "HEAD:${GITHUB_REF_NAME}" | |
| docker-publish: | |
| name: Publish Docker Images | |
| needs: generate-dockerfiles | |
| runs-on: ubuntu-latest | |
| permissions: | |
| packages: write | |
| contents: read | |
| attestations: write | |
| id-token: write | |
| continue-on-error: true | |
| strategy: | |
| matrix: ${{ fromJSON(needs.generate-dockerfiles.outputs.matrix) }} | |
| steps: | |
| - name: Random Wait | |
| uses: m3y/random-wait-action@v1 | |
| with: | |
| max-wait-time: 30 | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - name: Remove old Dockerfiles | |
| run: rm -rf dockerfiles | |
| - name: Download a Build Artifact | |
| uses: actions/download-artifact@v6 | |
| with: | |
| # Artifact name | |
| name: Dockerfiles | |
| # Destination path | |
| path: dockerfiles | |
| - name: Setup QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
| password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata (tags, labels) for Docker | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: | | |
| gameservermanagers/gameserver | |
| ghcr.io/gameservermanagers/gameserver | |
| tags: | | |
| ${{ matrix.shortname }} | |
| - name: Build and push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: dockerfiles/Dockerfile-${{ matrix.shortname }} | |
| platforms: linux/amd64 | |
| push: true | |
| build-args: | | |
| SHORTNAME=${{ matrix.shortname }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| package-cleanup: | |
| name: Cleanup Old GitHub Packages | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Delete old untagged package versions | |
| uses: snok/container-retention-policy@v3.0.1 | |
| with: | |
| account: GameServerManagers | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| image-names: gameserver | |
| tag-selection: untagged | |
| keep-n-most-recent: 1 | |
| cut-off: 1s | |
| dry-run: true | |
| package-cleanup-2: | |
| name: Cleanup Old GitHub Packages 2 | |
| needs: package-cleanup | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Delete old untagged package versions | |
| uses: snok/container-retention-policy@v3.0.1 | |
| with: | |
| account: GameServerManagers | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| image-names: gameserver | |
| tag-selection: untagged | |
| keep-n-most-recent: 1 | |
| cut-off: 1s | |
| dry-run: true | |
| package-cleanup-3: | |
| name: Cleanup Old GitHub Packages 3 | |
| needs: package-cleanup-2 | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Delete old untagged package versions | |
| uses: snok/container-retention-policy@v3.0.1 | |
| with: | |
| account: GameServerManagers | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| image-names: gameserver | |
| tag-selection: untagged | |
| keep-n-most-recent: 1 | |
| cut-off: 1s | |
| dry-run: true |