Skip to content

Commit

Permalink
New Github Workflows (#1)
Browse files Browse the repository at this point in the history
* Update dockerfile to build from source

* Add workflows for test on push, publish docker on release, and publish executbles on release

* typo

* updated name

* fixed finger problem
  • Loading branch information
mattkasun authored Nov 14, 2021
1 parent b220a61 commit c780284
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 47 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/buildandrelease.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Build and Release

on:
workflow_dispatch:
inputs:
version:
description: 'TimeTrace Version'
required: false
release:
types: [published]

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18 changes: 18 additions & 0 deletions .github/workflows/formatandtest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Format and Test

on:
push:

jobs:
tests:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: format
run: go fmt ./...
-
name: test
run: go test -v ./...
36 changes: 0 additions & 36 deletions .github/workflows/main.yml

This file was deleted.

60 changes: 60 additions & 0 deletions .github/workflows/publish-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Publish Docker

on:
workflow_dispatch:
inputs:
tag:
description: 'docker tag'
required: true
release:
types: [published]

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Set tag
id: set_tag
run: |
if [[ $GITHUB_EVENT_NAME == "workflow_dispatch" ]]; then
echo "VERSION=${{ github.event.inputs.tag }} " >> $GITHUB_ENV
elif [[ $GITHUB_EVENT_NAME == "release" ]]; then
echo "VERSION=$GITHUB_REF_NAME" >> $GITHUB_ENV
else
exit 1
fi
echo ${{ env.VERSION }}
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Login to Github Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push to Docker Hub
uses: docker/build-push-action@v2
with:
image: ${{ github.repository }}
context: .
platforms: linux/amd64
push: true
tags: ${{ env.VERSION }}
build-args: |
VERSION=${{ env.VERSION }}
29 changes: 29 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
16 changes: 6 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
# This Dockerfile builds a lightweight distribution image for Docker Hub.
# It only contains the application without any source code.
FROM alpine:3.11.5 AS downloader
FROM golang:latest as builder

# The timetrace release to be downloaded from GitHub.
ARG VERSION
WORKDIR /
COPY *.go go.* ./
RUN CGO_ENABLED=0 go build -mod=mod -a -installsuffix temp -ldflags "-extldflags '-static' -X 'main.version=${VERSION}'" .

RUN apk add --no-cache \
curl \
tar

RUN curl -LO https://github.com/dominikbraun/timetrace/releases/download/${VERSION}/timetrace-linux-amd64.tar.gz && \
tar -xvf timetrace-linux-amd64.tar.gz -C /bin && \
rm -f timetrace-linux-amd64.tar.gz

# The final stage. This is the image that will be distrubuted.
FROM alpine:3.11.5 AS final
Expand All @@ -25,10 +21,10 @@ LABEL org.label-schema.url="https://github.com/dominikbraun/timetrace"
LABEL org.label-schema.vcs-url="https://github.com/dominikbraun/timetrace"
LABEL org.label-schema.version=${VERSION}

COPY --from=downloader ["/bin/timetrace", "/bin/timetrace"]
COPY --from=builder ["/timetrace", "/bin/timetrace"]

# Create a symlink for musl, see https://stackoverflow.com/a/35613430.
RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
#RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2

RUN mkdir /etc/timetrace && \
echo "store: '/data'" >> /etc/timetrace/config.yml
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module github.com/dominikbraun/timetrace
module github.com/mattkasun/timetrace

go 1.15

require (
github.com/dominikbraun/timetrace v0.14.2
github.com/enescakir/emoji v1.0.0
github.com/fatih/color v1.13.0
github.com/olekukonko/tablewriter v0.0.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsr
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dominikbraun/timetrace v0.14.2 h1:ak3nOLBXS76fhdUoXYBxRJ4B12YwmMqJCYcbOQQDBsg=
github.com/dominikbraun/timetrace v0.14.2/go.mod h1:2ANn/NH3dvk1pTeNXlPDmHYQtr9M0lxeRUGdfG6LuOQ=
github.com/enescakir/emoji v1.0.0 h1:W+HsNql8swfCQFtioDGDHCHri8nudlK1n5p2rHCJoog=
github.com/enescakir/emoji v1.0.0/go.mod h1:Bt1EKuLnKDTYpLALApstIkAjdDrS/8IAgTkKp+WKFD0=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand Down
Binary file modified timetrace
Binary file not shown.

0 comments on commit c780284

Please sign in to comment.