Skip to content

Commit

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

* fix goreleaser config
  • Loading branch information
utkuufuk authored Apr 19, 2022
1 parent ddce29e commit d9a122d
Show file tree
Hide file tree
Showing 7 changed files with 175 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: github-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
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

docker-build:
name: Push Docker image to GitHub Packages
runs-on: ubuntu-latest
steps:
- name: Checkout
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/github-service/image
tags: ${{ steps.prep.outputs.tags }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.env
/.vscode
58 changes: 58 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
before:
hooks:
- go mod download

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

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

archives:
- id: github-service-archive
name_template: |-
github{{ .Tag }}_{{ .Os }}_{{ .Arch -}}
{{- with .Arm -}}
{{- if (eq . "6") -}}hf
{{- else -}}v{{- . -}}
{{- end -}}
{{- end -}}
builds:
- github-service-server
- github-service-cli
replacements:
386: i386
amd64: x86_64
format_overrides:
- goos: windows
format: zip
files: ["LICENSE"]

checksum:
name_template: "checksums.txt"
algorithm: sha256
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM golang:1.18-alpine as build
WORKDIR /src
COPY go.sum go.mod ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -o /bin/server ./cmd/server
RUN CGO_ENABLED=0 go build -o /bin/cli ./cmd/cli

FROM scratch
COPY --from=build /bin/server /bin/server
COPY --from=build /bin/cli /bin/cli
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
WORKDIR /bin
CMD ["./server"]
40 changes: 37 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# github-service
A simple service to query GitHub issues & pull requests.
* See [Server Mode](#server-mode) for using it as an [entrello](https://github.com/utkuufuk/entrello) service
* See [CLI Mode](#cli-mode) for using it as a CLI tool
* See [Server Mode](#server-mode) for using it as an [entrello](https://github.com/utkuufuk/entrello) service.
* See [CLI Mode](#cli-mode) for using it as a CLI tool.

## Configuration
Put your environment variables in a file called `.env`. See `.env.example` for reference.
Put your environment variables in a file called `.env`.

See `.env.example` for reference.


## Server Mode
Start the server:
Expand Down Expand Up @@ -44,3 +47,34 @@ go run ./cmd/cli prlo
go run ./cmd/cli prlmy
go run ./cmd/cli prlme
```

## Running With Docker
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).

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/github-service/image:latest
```

3. Start a container:
```sh
# server
docker run -d \
-p <PORT>:<PORT> \
--env-file </absolute/path/to/.env> \
--restart unless-stopped \
--name github-service \
ghcr.io/utkuufuk/github-service/image:latest
# CLI
docker run --rm \
-v </absolute/path/to/config.json>:/bin/config.json \
ghcr.io/utkuufuk/github-service/image:latest \
./cli
```

0 comments on commit d9a122d

Please sign in to comment.