@@ -2,29 +2,61 @@ name: Build Image
22
33on : [push, pull_request, workflow_dispatch]
44
5+ env :
6+ ENDPOINT : " linuxserver/mods" # don't modify
7+ BASEIMAGE : " replace_baseimage" # replace
8+ MODNAME : " replace_modname" # replace
9+
510jobs :
611 build :
7- env :
8- DOCKERHUB : " linuxserver/mods" # don't modify
9- BASEIMAGE : " baseimagename" # replace
10- MODNAME : " modname" # replace
11-
1212 runs-on : ubuntu-latest
1313 steps :
14141515
1616 - name : Build image
17- id : build
1817 run : |
19- docker build --no-cache -t ${DOCKERHUB}:${BASEIMAGE}-${MODNAME}-${ { github.sha }} .
18+ docker build --no-cache -t ${{ github.sha }} .
2019
21- - name : Push image
20+ - name : Tag image
2221 if : ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) }}
2322 run : |
24- # Tag image
25- docker tag ${DOCKERHUB}:${BASEIMAGE}-${MODNAME}-${{ github.sha }} ${DOCKERHUB}:${BASEIMAGE}-${MODNAME}
26- # Login to DockerHub
23+ docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}
24+ docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}
25+ docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}
26+ docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}
27+
28+ - name : Credential check
29+ if : ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) }}
30+ run : |
31+ echo "CR_USER=${{ secrets.CR_USER }}" >> $GITHUB_ENV
32+ echo "CR_PAT=${{ secrets.CR_PAT }}" >> $GITHUB_ENV
33+ echo "DOCKERUSER=${{ secrets.DOCKERUSER }}" >> $GITHUB_ENV
34+ echo "DOCKERPASS=${{ secrets.DOCKERPASS }}" >> $GITHUB_ENV
35+ if [[ "${{ secrets.CR_USER }}" == "" && "${{ secrets.CR_PAT }}" == "" && "${{ secrets.DOCKERUSER }}" == "" && "${{ secrets.DOCKERPASS }}" == "" ]]; then
36+ echo "::error::Push credential secrets missing."
37+ echo "::error::You must set either CR_USER & CR_PAT or DOCKERUSER & DOCKERPASS as secrets in your repo settings."
38+ echo "::error::See https://github.com/linuxserver/docker-mods/blob/master/README.md for more information/instructions."
39+ exit 1
40+ fi
41+
42+ - name : Login to GitHub Container Registry
43+ if : ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.CR_USER && env.CR_PAT }}
44+ run : |
45+ echo "${{ secrets.CR_PAT }}" | docker login ghcr.io -u ${{ secrets.CR_USER }} --password-stdin
46+
47+ - name : Push tags to GitHub Container Registry
48+ if : ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.CR_USER && env.CR_PAT }}
49+ run : |
50+ docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}
51+ docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}
52+
53+ - name : Login to DockerHub
54+ if : ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.DOCKERUSER && env.DOCKERPASS }}
55+ run : |
2756 echo ${{ secrets.DOCKERPASS }} | docker login -u ${{ secrets.DOCKERUSER }} --password-stdin
28- # Push all of the tags
29- docker push ${DOCKERHUB}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}
30- docker push ${DOCKERHUB}:${BASEIMAGE}-${MODNAME}
57+
58+ - name : Push tags to DockerHub
59+ if : ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.DOCKERUSER && env.DOCKERPASS }}
60+ run : |
61+ docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}
62+ docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}
0 commit comments