Skip to content

Commit 39e01aa

Browse files
authored
Merge pull request #134 from linuxserver/code-server-dotnet-gha-ghcr
Switch to GHA, add GHCR
2 parents 50c3a12 + 5459cb0 commit 39e01aa

3 files changed

Lines changed: 78 additions & 44 deletions

File tree

.github/workflows/BuildImage.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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: "dotnet" #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+
DOTNET_JSON="$(curl --retry 5 -sX GET https://raw.githubusercontent.com/dotnet/core/master/release-notes/releases-index.json)"
20+
DOTNET_VERSIONS="$(echo $DOTNET_JSON | jq -r '."releases-index"[] | select(."support-phase"=="lts") | ."latest-sdk"' | tr '\n' ' ' | head -c -1)"
21+
DOTNET_TAG="$(echo $DOTNET_VERSIONS | tr ' ' '_')"
22+
echo "DOTNET_TAG=${DOTNET_TAG}" >> $GITHUB_ENV
23+
# Build image
24+
docker build --no-cache --build-arg DOTNET_VERSIONS="${DOTNET_VERSIONS}" -t ${{ github.sha }} .
25+
26+
- name: Tag image
27+
if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) }}
28+
run: |
29+
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}
30+
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.DOTNET_TAG }}
31+
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.DOTNET_TAG }}-${{ github.sha }}
32+
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}
33+
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}
34+
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.DOTNET_TAG }}
35+
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.DOTNET_TAG }}-${{ github.sha }}
36+
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}
37+
38+
- name: Credential check
39+
if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) }}
40+
run: |
41+
echo "CR_USER=${{ secrets.CR_USER }}" >> $GITHUB_ENV
42+
echo "CR_PAT=${{ secrets.CR_PAT }}" >> $GITHUB_ENV
43+
echo "DOCKERUSER=${{ secrets.DOCKERUSER }}" >> $GITHUB_ENV
44+
echo "DOCKERPASS=${{ secrets.DOCKERPASS }}" >> $GITHUB_ENV
45+
if [[ "${{ secrets.CR_USER }}" == "" && "${{ secrets.CR_PAT }}" == "" && "${{ secrets.DOCKERUSER }}" == "" && "${{ secrets.DOCKERPASS }}" == "" ]]; then
46+
echo "::error::Push credential secrets missing."
47+
echo "::error::You must set either CR_USER & CR_PAT or DOCKERUSER & DOCKERPASS as secrets in your repo settings."
48+
echo "::error::See https://github.com/linuxserver/docker-mods/blob/master/README.md for more information/instructions."
49+
exit 1
50+
fi
51+
52+
- name: Login to GitHub Container Registry
53+
if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.CR_USER && env.CR_PAT }}
54+
run: |
55+
echo "${{ secrets.CR_PAT }}" | docker login ghcr.io -u ${{ secrets.CR_USER }} --password-stdin
56+
57+
- name: Push tags to GitHub Container Registry
58+
if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.CR_USER && env.CR_PAT }}
59+
run: |
60+
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.DOTNET_TAG }}
61+
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.DOTNET_TAG }}-${{ github.sha }}
62+
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}
63+
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}
64+
65+
- name: Login to DockerHub
66+
if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.DOCKERUSER && env.DOCKERPASS }}
67+
run: |
68+
echo ${{ secrets.DOCKERPASS }} | docker login -u ${{ secrets.DOCKERUSER }} --password-stdin
69+
70+
- name: Push tags to DockerHub
71+
if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.DOCKERUSER && env.DOCKERPASS }}
72+
run: |
73+
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.DOTNET_TAG }}
74+
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.DOTNET_TAG }}-${{ github.sha }}
75+
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}
76+
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}

.travis.yml

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

Dockerfile

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

33
ARG DOTNET_VERSIONS
44

@@ -39,4 +39,4 @@ FROM scratch
3939
LABEL maintainer="aptalca"
4040

4141
# Add files from buildstage
42-
COPY --from=buildstage /root-layer/ /
42+
COPY --from=buildstage /root-layer/ /

0 commit comments

Comments
 (0)