Skip to content

Commit 9b02568

Browse files
authored
Merge pull request #132 from linuxserver/code-server-golang-gha-ghcr
Switch to GHA, add GHCR
2 parents 442e78c + 2ebfef5 commit 9b02568

File tree

3 files changed

+117
-51
lines changed

3 files changed

+117
-51
lines changed

.github/workflows/BuildImage.yml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: Build Image
2+
3+
on: [push, pull_request, workflow_dispatch]
4+
5+
env:
6+
ENDPOINT: "linuxserver/mods" #don't modify
7+
BASEIMAGE: "code-server" #replace
8+
MODNAME: "golang" #replace
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/[email protected]
15+
16+
- name: Build image
17+
run: |
18+
# Set version
19+
GO_WEBSITE=$(curl -sX GET https://golang.org/dl/)
20+
GO_VERSION=${GO_VERSION:-$(echo "$GO_WEBSITE" | grep -o '<span.*>.*linux-amd64.*</span>' | grep -oP '(?<=go).*(?=.linux)')}
21+
if [ $(echo "$GO_VERSION" | tr -d -c '.' | awk '{ print length; }') = "1" ]; then GO_TAG="${GO_VERSION}.0"; else GO_TAG="${GO_VERSION}"; fi
22+
echo "GO_TAG=${GO_TAG}" >> $GITHUB_ENV
23+
GO_TAG_MINOR=$(echo "$GO_TAG" | awk 'BEGIN{FS=OFS="."} NF--')
24+
echo "GO_TAG_MINOR=${GO_TAG_MINOR}" >> $GITHUB_ENV
25+
GO_TAG_MAJOR=$(echo "$GO_TAG_MINOR" | awk 'BEGIN{FS=OFS="."} NF--')
26+
echo "GO_TAG_MAJOR=${GO_TAG_MAJOR}" >> $GITHUB_ENV
27+
echo "GO_TAG is $GO_TAG GO_TAG_MINOR is $GO_TAG_MINOR GO_TAG_MAJOR is $GO_TAG_MAJOR"
28+
if [ "$GO_VERSION" == $(echo "$GO_WEBSITE" | grep -o '<span.*>.*linux-amd64.*</span>' | grep -oP '(?<=go).*(?=.linux)') ]; then LATEST="true"; fi
29+
echo "LATEST=${LATEST}" >> $GITHUB_ENV
30+
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
31+
echo "LATEST_MINOR=${LATEST_MINOR}" >> $GITHUB_ENV
32+
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
33+
echo "LATEST_MAJOR=${LATEST_MAJOR}" >> $GITHUB_ENV
34+
echo "LATEST is ${LATEST:-not true}, LATEST_MINOR is ${LATEST_MINOR:-not true}, LATEST_MAJOR is ${LATEST_MAJOR:-not true}"
35+
# Build image
36+
docker build --no-cache --build-arg GO_VERSION=${GO_VERSION} -t ${{ github.sha }} .
37+
38+
- name: Tag image
39+
if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) }}
40+
run: |
41+
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}
42+
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG }}
43+
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG }}-${{ github.sha }}
44+
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MAJOR }}
45+
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MAJOR }}-${{ github.sha }}
46+
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MINOR }}
47+
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MINOR }}-${{ github.sha }}
48+
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}
49+
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}
50+
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG }}
51+
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG }}-${{ github.sha }}
52+
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MAJOR }}
53+
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MAJOR }}-${{ github.sha }}
54+
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MINOR }}
55+
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MINOR }}-${{ github.sha }}
56+
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}
57+
58+
- name: Credential check
59+
if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) }}
60+
run: |
61+
echo "CR_USER=${{ secrets.CR_USER }}" >> $GITHUB_ENV
62+
echo "CR_PAT=${{ secrets.CR_PAT }}" >> $GITHUB_ENV
63+
echo "DOCKERUSER=${{ secrets.DOCKERUSER }}" >> $GITHUB_ENV
64+
echo "DOCKERPASS=${{ secrets.DOCKERPASS }}" >> $GITHUB_ENV
65+
if [[ "${{ secrets.CR_USER }}" == "" && "${{ secrets.CR_PAT }}" == "" && "${{ secrets.DOCKERUSER }}" == "" && "${{ secrets.DOCKERPASS }}" == "" ]]; then
66+
echo "::error::Push credential secrets missing."
67+
echo "::error::You must set either CR_USER & CR_PAT or DOCKERUSER & DOCKERPASS as secrets in your repo settings."
68+
echo "::error::See https://github.com/linuxserver/docker-mods/blob/master/README.md for more information/instructions."
69+
exit 1
70+
fi
71+
72+
- name: Login to GitHub Container Registry
73+
if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.CR_USER && env.CR_PAT }}
74+
run: |
75+
echo "${{ secrets.CR_PAT }}" | docker login ghcr.io -u ${{ secrets.CR_USER }} --password-stdin
76+
77+
- name: Push tags to GitHub Container Registry
78+
if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.CR_USER && env.CR_PAT }}
79+
run: |
80+
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG }}-${{ github.sha }}
81+
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG }}
82+
if [ "${{ env.LATEST_MAJOR }}" == "true" ]; then
83+
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MAJOR }}-${{ github.sha }}
84+
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MAJOR }}
85+
fi
86+
if [ "${{ env.LATEST_MINOR }}" == "true" ]; then
87+
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MINOR }}-${{ github.sha }}
88+
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MINOR }}
89+
fi
90+
if [ "${{ env.LATEST }}" == "true" ]; then
91+
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}
92+
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}
93+
fi
94+
95+
- name: Login to DockerHub
96+
if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.DOCKERUSER && env.DOCKERPASS }}
97+
run: |
98+
echo ${{ secrets.DOCKERPASS }} | docker login -u ${{ secrets.DOCKERUSER }} --password-stdin
99+
100+
- name: Push tags to DockerHub
101+
if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.DOCKERUSER && env.DOCKERPASS }}
102+
run: |
103+
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG }}-${{ github.sha }}
104+
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG }}
105+
if [ "${{ env.LATEST_MAJOR }}" == "true" ]; then
106+
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MAJOR }}-${{ github.sha }}
107+
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MAJOR }}
108+
fi
109+
if [ "${{ env.LATEST_MINOR }}" == "true" ]; then
110+
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MINOR }}-${{ github.sha }}
111+
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.GO_TAG_MINOR }}
112+
fi
113+
if [ "${{ env.LATEST }}" == "true" ]; then
114+
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}
115+
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}
116+
fi

.travis.yml

Lines changed: 0 additions & 50 deletions
This file was deleted.

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM lsiobase/alpine:3.11 as buildstage
1+
FROM ghcr.io/linuxserver/baseimage-alpine:3.12 as buildstage
22

33
ARG GO_VERSION
44

0 commit comments

Comments
 (0)