Skip to content

Commit

Permalink
Dockerize (#15)
Browse files Browse the repository at this point in the history
* dockerize

* update goreleaser
  • Loading branch information
utkuufuk authored Apr 19, 2022
1 parent e520114 commit b5ba256
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 4 deletions.
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.editorconfig
.env.example
.gitignore
Dockerfile
LICENSE
Procfile
*.yml
*.json
*.md
/.git
/.github
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: habit-service
name: CI
on:
push:
jobs:
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Release

on:
push:
tags:
- 'v*.*.*'

jobs:
goreleaser:
name: Release new version
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master

- name: Unshallow
run: git fetch --prune --unshallow

- name: Setup Go
uses: actions/setup-go@v1
with:
go-version: 1.18.x

- name: GoReleaser
uses: goreleaser/goreleaser-action@v1
with:
version: latest
args: release --rm-dist
key: ${{ secrets.YOUR_PRIVATE_KEY }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

docker-build:
name: Push Docker image to GitHub Packages
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v2

- name: Prepare tags
id: prep
run: |
VERSION=${GITHUB_REF#refs/tags/}
TAGS="${VERSION},latest"
echo ::set-output name=tags::${TAGS}
- name: Push to GitHub Packages
uses: docker/build-push-action@v1
with:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: docker.pkg.github.com
repository: utkuufuk/habit-service/image
tags: ${{ steps.prep.outputs.tags }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.env
*.rest
*.png
/.vscode
73 changes: 73 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
before:
hooks:
- go mod download

builds:
- id: habit-service
main: ./cmd/habit-service
binary: habit-service
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
- windows
goarch:
- amd64
- arm
- arm64
goarm: [6, 7]

- id: progress-report
main: ./cmd/progress-report
binary: progress-report
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
- windows
goarch:
- amd64
- arm
- arm64
goarm: [6, 7]

- id: score-update
main: ./cmd/score-update
binary: score-update
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
- windows
goarch:
- amd64
- arm
- arm64
goarm: [6, 7]

archives:
- id: habit-service-archive
name_template: |-
habit_service_{{ .Tag }}_{{ .Os }}_{{ .Arch -}}
{{- with .Arm -}}
{{- if (eq . "6") -}}hf
{{- else -}}v{{- . -}}
{{- end -}}
{{- end -}}
builds:
- habit-service
- progress-report
- score-update
replacements:
386: i386
amd64: x86_64
format_overrides:
- goos: windows
format: zip

checksum:
name_template: "checksums.txt"
algorithm: sha256
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM golang:1.18-alpine as build
RUN apk --no-cache add tzdata
WORKDIR /src
COPY go.sum go.mod ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -o /bin/habit-service ./cmd/habit-service
RUN CGO_ENABLED=0 go build -o /bin/progress-report ./cmd/progress-report
RUN CGO_ENABLED=0 go build -o /bin/score-update ./cmd/score-update

FROM scratch
COPY --from=build /bin/habit-service /bin/habit-service
COPY --from=build /bin/progress-report /bin/progress-report
COPY --from=build /bin/score-update /bin/score-update
COPY --from=build /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
WORKDIR /bin
CMD ["./habit-service"]
42 changes: 40 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,40 @@
## Deploying to Heroku
The Heroku app is updated whenever a new commit is pushed to the `master` branch.
# habit-service
[![CI](https://github.com/utkuufuk/habit-service/actions/workflows/ci.yml/badge.svg)](https://github.com/utkuufuk/habit-service/actions/workflows/ci.yml)

Habit service for [entrello](https://github.com/utkuufuk/entrello)

## Running With Docker
A new [Docker image](https://github.com/utkuufuk?tab=packages&repo_name=habit-service) will be created upon each [release](https://github.com/utkuufuk/habit-service/releases).

1. Authenticate with the GitHub container registry (only once):
```sh
echo $GITHUB_ACCESS_TOKEN | docker login ghcr.io -u GITHUB_USERNAME --password-stdin
```

2. Pull the latest Docker image:
```sh
docker pull ghcr.io/utkuufuk/habit-service/image:latest
```

3. Start a container:
```sh
# habit service
docker run -d \
-p <PORT>:<PORT> \
--env-file </absolute/path/to/.env> \
--restart unless-stopped \
--name habit-service \
ghcr.io/utkuufuk/habit-service/image:latest
# score update runner
docker run --rm \
--env-file </absolute/path/to/.env> \
ghcr.io/utkuufuk/habit-service/image:latest \
./score-update
# progress report runner
docker run --rm \
--env-file </absolute/path/to/.env> \
ghcr.io/utkuufuk/habit-service/image:latest \
./progress-report
```

0 comments on commit b5ba256

Please sign in to comment.