Skip to content

Commit a1faf77

Browse files
moutonjeremyJeremy Mouton
andauthored
Add Docker support and CI pipelines (#2)
* rename file * rename go file * add dockerfile * add entrypoint script for start app * add 2 pipelines --------- Co-authored-by: Jeremy Mouton <jeremy.mouton@spendesk.com>
1 parent 163da8a commit a1faf77

File tree

6 files changed

+119
-1
lines changed

6 files changed

+119
-1
lines changed

.air.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ tmp_dir = "tmp"
55
[build]
66
bin = "./tmp/main"
77
args_bin = ["server", "-c", "./config.yaml"]
8-
cmd = "go build -o ./tmp/main cmd/main.go"
8+
cmd = "go build -o ./tmp/main cmd/cmd.go"
99
delay = 1000
1010
exclude_dir = ["assets", "tmp", "vendor", "testdata", "repositories"]
1111
exclude_file = []

.github/workflows/pr.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: PR
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write
10+
packages: write
11+
12+
jobs:
13+
build:
14+
name: Build
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
with:
21+
submodules: true
22+
23+
- uses: actions/setup-go@v5
24+
with:
25+
go-version-file: go.mod
26+
cache: true
27+
cache-dependency-path: go.sum
28+
29+
- uses: nowsprinting/check-version-format-action@v3
30+
if: github.event_name != 'pull_request'
31+
id: version
32+
with:
33+
prefix: 'v'
34+
35+
- name: Build app
36+
run: CGO_ENABLED=1 GOOS=linux go build -a -ldflags '-linkmode external -extldflags "-static" -X "main.version=${{ steps.version.outputs.full }}"' -o bin/app cmd/cmd.go

.github/workflows/release.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
contents: write
10+
packages: write
11+
12+
env:
13+
REGISTRY: ghcr.io
14+
IMAGE: ${{ github.repository }}
15+
16+
jobs:
17+
build:
18+
name: Build
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
with:
25+
submodules: true
26+
27+
- uses: actions/setup-go@v5
28+
with:
29+
go-version-file: go.mod
30+
cache: true
31+
cache-dependency-path: go.sum
32+
33+
- uses: nowsprinting/check-version-format-action@v3
34+
if: github.event_name != 'pull_request'
35+
id: version
36+
with:
37+
prefix: 'v'
38+
39+
- name: Build app
40+
run: CGO_ENABLED=1 GOOS=linux go build -a -ldflags '-linkmode external -extldflags "-static" -X "main.version=${{ steps.version.outputs.full }}"' -o bin/app cmd/cmd.go
41+
42+
- name: Docker meta
43+
id: meta
44+
uses: docker/metadata-action@v5
45+
with:
46+
images: ${{ env.REGISTRY }}/${{ env.IMAGE }}
47+
48+
- name: Log in to GitHub Container Registry
49+
uses: docker/login-action@v3
50+
if: github.event_name != 'pull_request'
51+
with:
52+
registry: ${{ env.REGISTRY }}
53+
username: ${{ github.actor }}
54+
password: ${{ secrets.GITHUB_TOKEN }}
55+
56+
- name: Build and push
57+
uses: docker/build-push-action@v5
58+
with:
59+
context: .
60+
file: ./Dockerfile
61+
push: ${{ github.event_name != 'pull_request' }}
62+
tags: ${{ steps.meta.outputs.tags }}
63+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM golang:1.23 as builder
2+
3+
WORKDIR /app
4+
COPY bin/app /app/bin/app
5+
6+
FROM alpine:latest as release
7+
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
8+
COPY --from=builder /app/bin/app .
9+
COPY entrypoint.sh /entrypoint.sh
10+
RUN chmod +x /entrypoint.sh
11+
ENTRYPOINT ["/entrypoint.sh"]
File renamed without changes.

entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# Start the migration
5+
# ./app migration -c /config/config.yaml
6+
7+
# Start the server
8+
exec ./app server -c /config/config.yaml

0 commit comments

Comments
 (0)