mirror of
https://github.com/linuxserver/github-workflows.git
synced 2026-03-02 00:02:48 +08:00
Merge pull request #22 from linuxserver/v1-mod-builder
add callable docker mod builder
This commit is contained in:
commit
602dc52ee2
132
.github/workflows/docker-mod-builder.yml
vendored
Normal file
132
.github/workflows/docker-mod-builder.yml
vendored
Normal file
@ -0,0 +1,132 @@
|
||||
name: Docker Mod Builder
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
BASEIMAGE:
|
||||
required: true
|
||||
type: string
|
||||
MODNAME:
|
||||
required: true
|
||||
type: string
|
||||
ENDPOINT:
|
||||
required: true
|
||||
type: string
|
||||
GITHUB_REPO:
|
||||
required: true
|
||||
type: string
|
||||
MOD_VERSION:
|
||||
required: false
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Dump payload
|
||||
env:
|
||||
GITHUB_CONTEXT: ${{ toJson(github) }}
|
||||
run: |
|
||||
echo "$GITHUB_CONTEXT"
|
||||
|
||||
- name: Set Vars
|
||||
run: |
|
||||
echo "BASEIMAGE=${{ inputs.BASEIMAGE }}" >> $GITHUB_ENV
|
||||
echo "MODNAME=${{ inputs.MODNAME }}" >> $GITHUB_ENV
|
||||
echo "ENDPOINT=${{ inputs.ENDPOINT }}" >> $GITHUB_ENV
|
||||
echo "GITHUB_REPO=${{ inputs.GITHUB_REPO }}" >> $GITHUB_ENV
|
||||
echo "MOD_VERSION=${{ inputs.MOD_VERSION }}" >> $GITHUB_ENV
|
||||
|
||||
- name: Dump vars
|
||||
run: |
|
||||
echo "BASEIMAGE is ${BASEIMAGE}"
|
||||
echo "GITHUB_REPO is ${GITHUB_REPO}"
|
||||
echo "MODNAME is ${MODNAME}"
|
||||
echo "ENDPOINT is ${ENDPOINT}"
|
||||
echo "MOD_VERSION is ${MOD_VERSION}"
|
||||
echo "github.repository is ${{ github.repository }}"
|
||||
echo "github.event.pull_request.base.ref is ${{ github.event.pull_request.base.ref }}"
|
||||
echo "github.event.pull_request.base.repo.name is ${{ github.event.pull_request.base.repo.name }}"
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2
|
||||
|
||||
- name: Build image
|
||||
run: |
|
||||
docker buildx build --no-cache --build-arg MOD_VERSION=${MOD_VERSION} -t ${{ github.sha }} .
|
||||
|
||||
- name: Tag image (Commit)
|
||||
if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.GITHUB_REPO == github.repository }}
|
||||
run: |
|
||||
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}
|
||||
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}
|
||||
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}
|
||||
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}
|
||||
if [[ -n "${MOD_VERSION}" ]]; then
|
||||
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${MOD_VERSION}
|
||||
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${MOD_VERSION}-${{ github.sha }}
|
||||
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${MOD_VERSION}
|
||||
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${MOD_VERSION}-${{ github.sha }}
|
||||
fi
|
||||
|
||||
- name: Tag image (PR)
|
||||
if: ${{ github.event.pull_request.base.ref == format('{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.GITHUB_REPO == format('{0}/{1}', github.event.pull_request.base.repo.owner.login, github.event.pull_request.base.repo.name) }}
|
||||
run: |
|
||||
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-pull_request_${{ github.event.pull_request.number }}
|
||||
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-pull_request_${{ github.event.pull_request.number }}
|
||||
|
||||
- name: Credential check
|
||||
if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.GITHUB_REPO == github.repository || github.event.pull_request.base.ref == format('{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.GITHUB_REPO == format('{0}/{1}', github.event.pull_request.base.repo.owner.login, github.event.pull_request.base.repo.name) }}
|
||||
run: |
|
||||
echo "CR_USER=${{ secrets.CR_USER }}" >> $GITHUB_ENV
|
||||
echo "CR_PAT=${{ secrets.CR_PAT }}" >> $GITHUB_ENV
|
||||
echo "DOCKERUSER=${{ secrets.DOCKERUSER }}" >> $GITHUB_ENV
|
||||
echo "DOCKERPASS=${{ secrets.DOCKERPASS }}" >> $GITHUB_ENV
|
||||
if [[ "${{ secrets.CR_USER }}" == "" && "${{ secrets.CR_PAT }}" == "" && "${{ secrets.DOCKERUSER }}" == "" && "${{ secrets.DOCKERPASS }}" == "" ]]; then
|
||||
echo "::error::Push credential secrets missing."
|
||||
echo "::error::You must set either CR_USER & CR_PAT or DOCKERUSER & DOCKERPASS as secrets in your repo settings."
|
||||
echo "::error::See https://github.com/linuxserver/docker-mods/blob/master/README.md for more information/instructions."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
if: ${{ (github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.GITHUB_REPO == github.repository || github.event.pull_request.base.ref == format('{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.GITHUB_REPO == format('{0}/{1}', github.event.pull_request.base.repo.owner.login, github.event.pull_request.base.repo.name)) && env.CR_USER && env.CR_PAT }}
|
||||
run: |
|
||||
echo "${{ secrets.CR_PAT }}" | docker login ghcr.io -u ${{ secrets.CR_USER }} --password-stdin
|
||||
|
||||
- name: Push tags to GitHub Container Registry (Commit)
|
||||
if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.GITHUB_REPO == github.repository && env.CR_USER && env.CR_PAT }}
|
||||
run: |
|
||||
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}
|
||||
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}
|
||||
if [[ -n "${MOD_VERSION}" ]]; then
|
||||
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${MOD_VERSION}
|
||||
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${MOD_VERSION}-${{ github.sha }}
|
||||
fi
|
||||
|
||||
- name: Push tags to GitHub Container Registry (PR)
|
||||
if: ${{ github.event.pull_request.base.ref == format('{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.GITHUB_REPO == format('{0}/{1}', github.event.pull_request.base.repo.owner.login, github.event.pull_request.base.repo.name) && env.CR_USER && env.CR_PAT }}
|
||||
run: |
|
||||
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-pull_request_${{ github.event.pull_request.number }}
|
||||
|
||||
- name: Login to DockerHub
|
||||
if: ${{ (github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.GITHUB_REPO == github.repository || github.event.pull_request.base.ref == format('{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.GITHUB_REPO == format('{0}/{1}', github.event.pull_request.base.repo.owner.login, github.event.pull_request.base.repo.name)) && env.DOCKERUSER && env.DOCKERPASS }}
|
||||
run: |
|
||||
echo ${{ secrets.DOCKERPASS }} | docker login -u ${{ secrets.DOCKERUSER }} --password-stdin
|
||||
|
||||
- name: Push tags to DockerHub (Commit)
|
||||
if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.GITHUB_REPO == github.repository && env.DOCKERUSER && env.DOCKERPASS }}
|
||||
run: |
|
||||
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}
|
||||
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}
|
||||
if [[ -n "${MOD_VERSION}" ]]; then
|
||||
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${MOD_VERSION}
|
||||
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${MOD_VERSION}-${{ github.sha }}
|
||||
fi
|
||||
|
||||
- name: Push tags to DockerHub (PR)
|
||||
if: ${{ github.event.pull_request.base.ref == format('{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.GITHUB_REPO == format('{0}/{1}', github.event.pull_request.base.repo.owner.login, github.event.pull_request.base.repo.name) && env.DOCKERUSER && env.DOCKERPASS }}
|
||||
run: |
|
||||
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-pull_request_${{ github.event.pull_request.number }}
|
||||
Loading…
x
Reference in New Issue
Block a user