Build Image #3297
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: Build Image | |
on: | |
push: | |
pull_request: | |
workflow_dispatch: | |
inputs: | |
GO_VERSION: | |
env: | |
ENDPOINT: "linuxserver/mods" #don't modify | |
BASEIMAGE: "code-server" #replace | |
MODNAME: "golang" #replace | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Build image | |
run: | | |
# Set version | |
GO_WEBSITE=$(curl -sLX GET https://go.dev/dl/) | |
GO_VERSION=${{ github.event.inputs.GO_VERSION }} | |
GO_VERSION=${GO_VERSION:-$(echo "$GO_WEBSITE" | grep -o '<span.*>.*linux-amd64.*</span>' | grep -oP '(?<=go).*(?=.linux)')} | |
if [ $(echo "$GO_VERSION" | tr -d -c '.' | awk '{ print length; }') = "1" ]; then GO_TAG="${GO_VERSION}.0"; else GO_TAG="${GO_VERSION}"; fi | |
echo "GO_TAG=${GO_TAG}" >> $GITHUB_ENV | |
GO_TAG_MINOR=$(echo "$GO_TAG" | awk 'BEGIN{FS=OFS="."} NF--') | |
echo "GO_TAG_MINOR=${GO_TAG_MINOR}" >> $GITHUB_ENV | |
GO_TAG_MAJOR=$(echo "$GO_TAG_MINOR" | awk 'BEGIN{FS=OFS="."} NF--') | |
echo "GO_TAG_MAJOR=${GO_TAG_MAJOR}" >> $GITHUB_ENV | |
echo "GO_TAG is $GO_TAG GO_TAG_MINOR is $GO_TAG_MINOR GO_TAG_MAJOR is $GO_TAG_MAJOR" | |
if [ "$GO_VERSION" == $(echo "$GO_WEBSITE" | grep -o '<span.*>.*linux-amd64.*</span>' | grep -oP '(?<=go).*(?=.linux)') ]; then LATEST="true"; fi | |
echo "LATEST=${LATEST}" >> $GITHUB_ENV | |
if [ "$GO_VERSION" == $(echo "$GO_WEBSITE" | grep -o 'download" href=".*linux-amd64.tar.gz">' | grep -oP '(?<=\/go)[1-9].*(?=.linux)' | grep -m 1 ^${GO_TAG_MINOR}) ]; then LATEST_MINOR="true"; fi | |
echo "LATEST_MINOR=${LATEST_MINOR}" >> $GITHUB_ENV | |
if [ "$GO_VERSION" == $(echo "$GO_WEBSITE" | grep -o 'download" href=".*linux-amd64.tar.gz">' | grep -oP '(?<=\/go)[1-9].*(?=.linux)' | grep -m 1 ^${GO_TAG_MAJOR}) ]; then LATEST_MAJOR="true"; fi | |
echo "LATEST_MAJOR=${LATEST_MAJOR}" >> $GITHUB_ENV | |
echo "LATEST is ${LATEST:-not true}, LATEST_MINOR is ${LATEST_MINOR:-not true}, LATEST_MAJOR is ${LATEST_MAJOR:-not true}" | |
# Build image | |
docker build --no-cache --build-arg GO_VERSION=${GO_VERSION} -t ${{ github.sha }} . | |
- name: Tag image | |
if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) }} | |
run: | | |
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME} | |
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG }} | |
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG }}-${{ github.sha }} | |
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MAJOR }} | |
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MAJOR }}-${{ github.sha }} | |
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MINOR }} | |
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MINOR }}-${{ github.sha }} | |
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}-${{ env.GO_TAG }} | |
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG }}-${{ github.sha }} | |
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MAJOR }} | |
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MAJOR }}-${{ github.sha }} | |
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MINOR }} | |
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MINOR }}-${{ github.sha }} | |
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }} | |
- name: Credential check | |
if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) }} | |
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.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 | |
if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.CR_USER && env.CR_PAT }} | |
run: | | |
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG }}-${{ github.sha }} | |
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG }} | |
if [ "${{ env.LATEST_MAJOR }}" == "true" ]; then | |
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MAJOR }}-${{ github.sha }} | |
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MAJOR }} | |
fi | |
if [ "${{ env.LATEST_MINOR }}" == "true" ]; then | |
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MINOR }}-${{ github.sha }} | |
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MINOR }} | |
fi | |
if [ "${{ env.LATEST }}" == "true" ]; then | |
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }} | |
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME} | |
fi | |
- name: Login to DockerHub | |
if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.DOCKERUSER && env.DOCKERPASS }} | |
run: | | |
echo ${{ secrets.DOCKERPASS }} | docker login -u ${{ secrets.DOCKERUSER }} --password-stdin | |
- name: Push tags to DockerHub | |
if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.DOCKERUSER && env.DOCKERPASS }} | |
run: | | |
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG }}-${{ github.sha }} | |
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG }} | |
if [ "${{ env.LATEST_MAJOR }}" == "true" ]; then | |
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MAJOR }}-${{ github.sha }} | |
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MAJOR }} | |
fi | |
if [ "${{ env.LATEST_MINOR }}" == "true" ]; then | |
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MINOR }}-${{ github.sha }} | |
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MINOR }} | |
fi | |
if [ "${{ env.LATEST }}" == "true" ]; then | |
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }} | |
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME} | |
fi |