Docker Publish #498
This file contains 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.yml" | |
- "requirements.txt" | |
- "Dockerfile.j2" | |
- "docker-compose.yml.j2" | |
schedule: | |
- cron: "0 3 * * 6" | |
jobs: | |
generate-dockerfiles: | |
name: Generate Dockerfiles | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Generate python | |
uses: actions/setup-python@v5 | |
with: | |
cache: "pip" | |
- run: pip3 install -r requirements.txt | |
- name: Generate Dockerfile with generate-dockerfiles.sh | |
run: ./generate-dockerfiles.sh | |
- name: Upload a Build Artifact | |
uses: actions/[email protected] | |
with: | |
# Artifact name | |
name: Dockerfiles | |
# A file, directory or wildcard pattern that describes what to upload | |
path: dockerfiles | |
- name: Push commit | |
uses: EndBug/add-and-commit@v9 | |
with: | |
message: "Generate Dockerfiles" | |
add: "dockerfiles/Dockerfile*" | |
- 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 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup python | |
uses: actions/setup-python@v5 | |
with: | |
cache: "pip" | |
- run: pip3 install -r requirements.txt | |
- name: Generate docker-compose.yml files with generate-docker-compose.sh | |
run: ./generate-docker-compose.sh | |
- name: Push commit | |
uses: EndBug/add-and-commit@v9 | |
with: | |
message: "Generate docker-compose.yml files" | |
add: "docker-compose/docker-compose*" | |
docker-publish: | |
name: Publish Docker Images | |
needs: generate-dockerfiles | |
runs-on: ubuntu-latest | |
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@v4 | |
- name: Remove old Dockerfiles | |
run: rm -rf dockerfiles | |
- name: Download a Build Artifact | |
uses: actions/[email protected] | |
with: | |
# Artifact name | |
name: Dockerfiles | |
# Destination path | |
path: dockerfiles | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/[email protected] | |
- name: Login to DockerHub | |
uses: docker/[email protected] | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
- name: Login to GitHub Container Registry | |
uses: docker/[email protected] | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push | |
uses: docker/[email protected] | |
with: | |
context: . | |
file: dockerfiles/Dockerfile.${{ matrix.shortname }} | |
platforms: linux/amd64 | |
push: true | |
build-args: | | |
SHORTNAME=${{ matrix.shortname }} | |
tags: | | |
gameservermanagers/gameserver:${{ matrix.shortname }} | |
ghcr.io/gameservermanagers/gameserver:${{ matrix.shortname }} | |
package-cleanup: | |
name: Cleanup Old GitHub Packages | |
runs-on: ubuntu-latest | |
steps: | |
- name: Delete Package Versions | |
uses: actions/delete-package-versions@v5 | |
with: | |
package-name: gameserver | |
package-type: container | |
min-versions-to-keep: 1 | |
delete-only-untagged-versions: true | |
package-cleanup-2: | |
name: Cleanup Old GitHub Packages 2 | |
needs: package-cleanup | |
runs-on: ubuntu-latest | |
steps: | |
- name: Delete Package Versions | |
uses: actions/delete-package-versions@v5 | |
with: | |
package-name: gameserver | |
package-type: container | |
min-versions-to-keep: 1 | |
delete-only-untagged-versions: true | |
package-cleanup-3: | |
name: Cleanup Old GitHub Packages 3 | |
needs: package-cleanup-2 | |
runs-on: ubuntu-latest | |
steps: | |
- name: Delete Package Versions | |
uses: actions/delete-package-versions@v5 | |
with: | |
package-name: gameserver | |
package-type: container | |
min-versions-to-keep: 1 | |
delete-only-untagged-versions: true |