Skip to content

Commit

Permalink
Merge pull request #174 from sharkwouter/add-container
Browse files Browse the repository at this point in the history
Add Docker container that is automatically build for releases
  • Loading branch information
nvthongswansea authored May 16, 2024
2 parents f5a7195 + 2e66f90 commit e88bbd0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Docker

on:
push:
tags:
- "*"

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true

- name: Create RELEASE.txt
run: |
echo "GIT_COMMIT=${{ github.sha }}" > RELEASE.txt
echo "VERSION=${{ github.ref_name }}" >> RELEASE.txt
cat RELEASE.txt
- name: Login to GitHub registry
uses: docker/login-action@v3
with:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io

- name: Build and push Docker container to GitHub registry
uses: docker/build-push-action@v5
with:
context: .
push: true
labels: |
git_commit=${{ github.sha }}
version=${{ github.ref_name }}
tags: |
ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:${{ github.ref_name }}
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM golang:alpine

COPY . /src

RUN cd /src && \
apk add --no-cache make git && \
make

FROM alpine:latest

COPY --from=0 /src/gscloud /usr/bin/gscloud
ENTRYPOINT ["/usr/bin/gscloud"]
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
VERSION := $(shell if ! git describe --tags 2>/dev/null; then \
grep -Po '(?<=^VERSION=)v.*$$' $$PWD/RELEASE.txt; \
grep '^VERSION=' $$PWD/RELEASE.txt|cut -d'=' -f2-; \
fi; \
)

GIT_COMMIT := $(shell if ! git rev-list -1 HEAD 2>/dev/null; then \
grep -Po '(?<=^GIT_COMMIT=)\w*$$' $$PWD/RELEASE.txt; \
grep '^GIT_COMMIT=' $$PWD/RELEASE.txt|cut -d'=' -f2-; \
fi; \
)

Expand Down

0 comments on commit e88bbd0

Please sign in to comment.