name: Build Docker Package on: push: branches: - master tags: - "v*" workflow_dispatch: jobs: docker-package: runs-on: ubuntu-latest env: REGISTRY: git.hanhan.ltd NODE_IMAGE: m.daocloud.io/docker.io/library/node:22 NPM_REGISTRY: https://registry.npmmirror.com steps: - name: Checkout uses: actions/checkout@v4 - name: Prepare image metadata id: meta shell: bash run: | repository="${GITHUB_REPOSITORY:-${{ gitea.repository }}}" repository="$(printf '%s' "$repository" | tr '[:upper:]' '[:lower:]')" image="${REGISTRY}/${repository}" sha="${GITHUB_SHA:-${{ gitea.sha }}}" short_sha="${sha:0:12}" ref="${GITHUB_REF:-${{ gitea.ref }}}" { echo "image=${image}" echo "tags<> "${GITHUB_OUTPUT}" - name: Login to Gitea container registry env: PACKAGE_USERNAME: ${{ secrets.PACKAGE_USERNAME }} PACKAGE_TOKEN: ${{ secrets.PACKAGE_TOKEN }} GITEA_ACTOR: ${{ gitea.actor }} shell: bash run: | username="${PACKAGE_USERNAME:-${GITEA_ACTOR}}" if [[ -z "${PACKAGE_TOKEN}" ]]; then echo "PACKAGE_TOKEN secret is required to publish container packages." >&2 echo "Create a Gitea personal access token with package write permission and save it as PACKAGE_TOKEN." >&2 exit 1 fi echo "${PACKAGE_TOKEN}" | docker login "${REGISTRY}" -u "${username}" --password-stdin - name: Build image shell: bash run: | mapfile -t tags <<< "${{ steps.meta.outputs.tags }}" args=() for tag in "${tags[@]}"; do args+=(--tag "$tag") done docker build \ --build-arg "NODE_IMAGE=${NODE_IMAGE}" \ --build-arg "NPM_REGISTRY=${NPM_REGISTRY}" \ "${args[@]}" \ . - name: Push image shell: bash run: | mapfile -t tags <<< "${{ steps.meta.outputs.tags }}" for tag in "${tags[@]}"; do docker push "$tag" done