Skip to content

Commit d9a122d

Browse files
authored
Dockerize (#1)
* dockerize * fix goreleaser config
1 parent ddce29e commit d9a122d

File tree

7 files changed

+175
-4
lines changed

7 files changed

+175
-4
lines changed

.dockerignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.editorconfig
2+
.env.example
3+
.gitignore
4+
Dockerfile
5+
LICENSE
6+
Procfile
7+
*.yml
8+
*.json
9+
*.md
10+
/.git
11+
/.github

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: github-service
1+
name: CI
22
on:
33
push:
44
jobs:

.github/workflows/release.yml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
jobs:
9+
goreleaser:
10+
name: Release new version
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@master
15+
16+
- name: Unshallow
17+
run: git fetch --prune --unshallow
18+
19+
- name: Setup Go
20+
uses: actions/setup-go@v1
21+
with:
22+
go-version: 1.18.x
23+
24+
- name: GoReleaser
25+
uses: goreleaser/goreleaser-action@v1
26+
with:
27+
version: latest
28+
args: release --rm-dist
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
32+
docker-build:
33+
name: Push Docker image to GitHub Packages
34+
runs-on: ubuntu-latest
35+
steps:
36+
- name: Checkout
37+
uses: actions/checkout@v2
38+
39+
- name: Prepare tags
40+
id: prep
41+
run: |
42+
VERSION=${GITHUB_REF#refs/tags/}
43+
TAGS="${VERSION},latest"
44+
echo ::set-output name=tags::${TAGS}
45+
46+
- name: Push to GitHub Packages
47+
uses: docker/build-push-action@v1
48+
with:
49+
username: ${{ github.actor }}
50+
password: ${{ secrets.GITHUB_TOKEN }}
51+
registry: docker.pkg.github.com
52+
repository: utkuufuk/github-service/image
53+
tags: ${{ steps.prep.outputs.tags }}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.env
2+
/.vscode

.goreleaser.yml

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
before:
2+
hooks:
3+
- go mod download
4+
5+
builds:
6+
- id: github-service-server
7+
main: ./cmd/server
8+
binary: server
9+
env:
10+
- CGO_ENABLED=0
11+
goos:
12+
- linux
13+
- darwin
14+
- windows
15+
goarch:
16+
- amd64
17+
- arm
18+
- arm64
19+
goarm: [6, 7]
20+
21+
- id: github-service-cli
22+
main: ./cmd/cli
23+
binary: cli
24+
env:
25+
- CGO_ENABLED=0
26+
goos:
27+
- linux
28+
- darwin
29+
- windows
30+
goarch:
31+
- amd64
32+
- arm
33+
- arm64
34+
goarm: [6, 7]
35+
36+
archives:
37+
- id: github-service-archive
38+
name_template: |-
39+
github{{ .Tag }}_{{ .Os }}_{{ .Arch -}}
40+
{{- with .Arm -}}
41+
{{- if (eq . "6") -}}hf
42+
{{- else -}}v{{- . -}}
43+
{{- end -}}
44+
{{- end -}}
45+
builds:
46+
- github-service-server
47+
- github-service-cli
48+
replacements:
49+
386: i386
50+
amd64: x86_64
51+
format_overrides:
52+
- goos: windows
53+
format: zip
54+
files: ["LICENSE"]
55+
56+
checksum:
57+
name_template: "checksums.txt"
58+
algorithm: sha256

Dockerfile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM golang:1.18-alpine as build
2+
WORKDIR /src
3+
COPY go.sum go.mod ./
4+
RUN go mod download
5+
COPY . .
6+
RUN CGO_ENABLED=0 go build -o /bin/server ./cmd/server
7+
RUN CGO_ENABLED=0 go build -o /bin/cli ./cmd/cli
8+
9+
FROM scratch
10+
COPY --from=build /bin/server /bin/server
11+
COPY --from=build /bin/cli /bin/cli
12+
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
13+
WORKDIR /bin
14+
CMD ["./server"]

README.md

+37-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# github-service
22
A simple service to query GitHub issues & pull requests.
3-
* See [Server Mode](#server-mode) for using it as an [entrello](https://github.com/utkuufuk/entrello) service
4-
* See [CLI Mode](#cli-mode) for using it as a CLI tool
3+
* See [Server Mode](#server-mode) for using it as an [entrello](https://github.com/utkuufuk/entrello) service.
4+
* See [CLI Mode](#cli-mode) for using it as a CLI tool.
55

66
## Configuration
7-
Put your environment variables in a file called `.env`. See `.env.example` for reference.
7+
Put your environment variables in a file called `.env`.
8+
9+
See `.env.example` for reference.
10+
811

912
## Server Mode
1013
Start the server:
@@ -44,3 +47,34 @@ go run ./cmd/cli prlo
4447
go run ./cmd/cli prlmy
4548
go run ./cmd/cli prlme
4649
```
50+
51+
## Running With Docker
52+
A new [Docker image](https://github.com/utkuufuk?tab=packages&repo_name=github-service) will be created upon each [release](https://github.com/utkuufuk/github-service/releases).
53+
54+
1. Authenticate with the GitHub container registry (only once):
55+
```sh
56+
echo $GITHUB_ACCESS_TOKEN | docker login ghcr.io -u GITHUB_USERNAME --password-stdin
57+
```
58+
59+
2. Pull the latest Docker image:
60+
```sh
61+
docker pull ghcr.io/utkuufuk/github-service/image:latest
62+
```
63+
64+
3. Start a container:
65+
```sh
66+
# server
67+
docker run -d \
68+
-p <PORT>:<PORT> \
69+
--env-file </absolute/path/to/.env> \
70+
--restart unless-stopped \
71+
--name github-service \
72+
ghcr.io/utkuufuk/github-service/image:latest
73+
74+
# CLI
75+
docker run --rm \
76+
-v </absolute/path/to/config.json>:/bin/config.json \
77+
ghcr.io/utkuufuk/github-service/image:latest \
78+
./cli
79+
```
80+

0 commit comments

Comments
 (0)