Skip to content

Commit

Permalink
Publish docker image in GHCR (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto authored Feb 28, 2022
1 parent 4cac08d commit ed57e37
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Determine Version
run: |
# determine version from tag
export VERSION=$(echo "${GITHUB_REF}" | cut -d "/" -f3)
if [[ $VERSION != v* ]]
then
export VERSION=""
echo "Building version-less (main or feature branch)"
else
# make version more Docker-friendly by dropping the 'v'
export VERSION=${VERSION:1:${#VERSION}}
echo "Building as ${VERSION}"
fi
echo "##[set-output name=version;]$VERSION"
id: determine_version

- name: Set up Go
uses: actions/setup-go@v2
with:
Expand All @@ -30,3 +46,14 @@ jobs:
with:
files: coverage.cov
flags: unittests

- name: Push Release Docker Image
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
docker build -t ghcr.io/oxisto/oauth2go:latest .
docker tag ghcr.io/oxisto/oauth2go:latest ghcr.io/oxisto/oauth2go:$VERSION
docker push ghcr.io/oxisto/oauth2go:$VERSION
docker push ghcr.io/oxisto/oauth2go:latest
if: startsWith(github.ref, 'refs/tags/v')
env:
VERSION: ${{ steps.determine_version.outputs.version }}
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM golang as builder

WORKDIR /build

ADD go.mod .
ADD go.sum .

ADD . .

# Disable cgo because our final image will be alpine and will not have the same C stdlib
RUN CGO_ENABLED=0 go build cmd/server/server.go

FROM alpine

COPY --from=builder /build/server /

CMD ["./server"]

0 comments on commit ed57e37

Please sign in to comment.