package-server-images #13
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: package-server-images | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| source_ref: | |
| description: Git ref to package | |
| required: false | |
| default: Playerbot | |
| image_tag: | |
| description: Optional image tag. If empty and latest is unchecked, acore.json version is used. | |
| required: false | |
| default: "" | |
| platforms: | |
| description: Docker platforms to build | |
| required: false | |
| default: linux/amd64 | |
| push_images: | |
| description: Push images to configured registries | |
| required: false | |
| type: boolean | |
| default: true | |
| tag_latest: | |
| description: Also publish the latest tag. With an empty image_tag, only latest and sha tags are published. | |
| required: false | |
| type: boolean | |
| default: false | |
| jobs: | |
| package: | |
| runs-on: ubuntu-22.04 | |
| permissions: | |
| contents: read | |
| packages: write | |
| env: | |
| GHCR_REGISTRY: ghcr.io | |
| IMAGE_NAMESPACE: ${{ github.repository_owner }} | |
| REPOSITORY_NAME: ${{ github.event.repository.name }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ inputs.source_ref }} | |
| - name: Prepare bundled modules | |
| shell: bash | |
| run: | | |
| bash apps/docker/prepare-bundled-modules.sh modules | |
| - name: Detect Aliyun Registry Config | |
| id: aliyun | |
| shell: bash | |
| env: | |
| ALIYUN_REGISTRY: ${{ secrets.ALIYUN_REGISTRY }} | |
| ALIYUN_NAMESPACE: ${{ secrets.ALIYUN_NAME_SPACE }} | |
| ALIYUN_REGISTRY_USER: ${{ secrets.ALIYUN_REGISTRY_USER }} | |
| ALIYUN_REGISTRY_PASSWORD: ${{ secrets.ALIYUN_REGISTRY_PASSWORD }} | |
| run: | | |
| set -euo pipefail | |
| if [[ -n "${ALIYUN_REGISTRY}" && -n "${ALIYUN_NAMESPACE}" && -n "${ALIYUN_REGISTRY_USER}" && -n "${ALIYUN_REGISTRY_PASSWORD}" ]]; then | |
| echo "enabled=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "enabled=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Resolve image names and tags | |
| id: meta | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| requested_tag="${{ inputs.image_tag }}" | |
| version_tag="$(jq -r '.version' acore.json)" | |
| sha_tag="sha-${GITHUB_SHA::12}" | |
| latest_tag="" | |
| image_tag="" | |
| image_namespace="$(printf '%s' "${IMAGE_NAMESPACE}" | tr '[:upper:]' '[:lower:]')" | |
| repository_name="$(printf '%s' "${REPOSITORY_NAME}" | tr '[:upper:]' '[:lower:]')" | |
| ghcr_world_image="${GHCR_REGISTRY}/${image_namespace}/${repository_name}-worldserver" | |
| ghcr_auth_image="${GHCR_REGISTRY}/${image_namespace}/${repository_name}-authserver" | |
| aliyun_world_image="" | |
| aliyun_auth_image="" | |
| if [[ "${{ inputs.tag_latest }}" == "true" ]]; then | |
| latest_tag="latest" | |
| fi | |
| if [[ -n "$requested_tag" ]]; then | |
| image_tag="$requested_tag" | |
| elif [[ "${{ inputs.tag_latest }}" != "true" ]]; then | |
| image_tag="$version_tag" | |
| fi | |
| emit_tags() { | |
| local image="$1" | |
| shift || true | |
| local tag | |
| declare -A seen=() | |
| [[ -n "$image" ]] || return 0 | |
| for tag in "$@"; do | |
| [[ -n "$tag" ]] || continue | |
| if [[ -z "${seen[$tag]:-}" ]]; then | |
| echo "${image}:${tag}" | |
| seen["$tag"]=1 | |
| fi | |
| done | |
| } | |
| if [[ "${{ steps.aliyun.outputs.enabled }}" == "true" ]]; then | |
| aliyun_world_image="${{ secrets.ALIYUN_REGISTRY }}/${{ secrets.ALIYUN_NAME_SPACE }}/${repository_name}-worldserver" | |
| aliyun_auth_image="${{ secrets.ALIYUN_REGISTRY }}/${{ secrets.ALIYUN_NAME_SPACE }}/${repository_name}-authserver" | |
| fi | |
| { | |
| echo "requested_tag=${requested_tag}" | |
| echo "version_tag=${version_tag}" | |
| echo "image_tag=${image_tag}" | |
| echo "sha_tag=${sha_tag}" | |
| echo "ghcr_world_image=${ghcr_world_image}" | |
| echo "ghcr_auth_image=${ghcr_auth_image}" | |
| echo "aliyun_world_image=${aliyun_world_image}" | |
| echo "aliyun_auth_image=${aliyun_auth_image}" | |
| echo "world_tags<<EOF" | |
| emit_tags "$ghcr_world_image" "$latest_tag" "$image_tag" "$sha_tag" | |
| emit_tags "$aliyun_world_image" "$latest_tag" "$image_tag" "$sha_tag" | |
| echo "EOF" | |
| echo "auth_tags<<EOF" | |
| emit_tags "$ghcr_auth_image" "$latest_tag" "$image_tag" "$sha_tag" | |
| emit_tags "$aliyun_auth_image" "$latest_tag" "$image_tag" "$sha_tag" | |
| echo "EOF" | |
| } >> "$GITHUB_OUTPUT" | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GHCR | |
| if: ${{ inputs.push_images }} | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.GHCR_REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Login to Aliyun Registry | |
| if: ${{ inputs.push_images && steps.aliyun.outputs.enabled == 'true' }} | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ secrets.ALIYUN_REGISTRY }} | |
| username: ${{ secrets.ALIYUN_REGISTRY_USER }} | |
| password: ${{ secrets.ALIYUN_REGISTRY_PASSWORD }} | |
| - name: Build worldserver image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: apps/docker/Dockerfile | |
| target: worldserver | |
| platforms: ${{ inputs.platforms }} | |
| push: ${{ inputs.push_images }} | |
| pull: true | |
| provenance: false | |
| tags: ${{ steps.meta.outputs.world_tags }} | |
| cache-from: | | |
| type=gha,scope=server-images | |
| type=gha,scope=worldserver | |
| cache-to: | | |
| type=gha,mode=max,scope=server-images | |
| type=gha,mode=max,scope=worldserver | |
| - name: Build authserver image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: apps/docker/Dockerfile | |
| target: authserver | |
| platforms: ${{ inputs.platforms }} | |
| push: ${{ inputs.push_images }} | |
| pull: true | |
| provenance: false | |
| tags: ${{ steps.meta.outputs.auth_tags }} | |
| cache-from: | | |
| type=gha,scope=server-images | |
| type=gha,scope=authserver | |
| cache-to: | | |
| type=gha,mode=max,scope=server-images | |
| type=gha,mode=max,scope=authserver | |
| - name: Print image references | |
| shell: bash | |
| run: | | |
| echo "worldserver:" | |
| echo "${{ steps.meta.outputs.world_tags }}" | |
| echo | |
| echo "authserver:" | |
| echo "${{ steps.meta.outputs.auth_tags }}" |