Skip to content

Commit 7177a63

Browse files
authored
Merge pull request #1 from chickenzord/feat/docker
feat: Dockerize
2 parents f423ff4 + ddce526 commit 7177a63

File tree

6 files changed

+141
-5
lines changed

6 files changed

+141
-5
lines changed

.github/workflows/docker.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Docker
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
tags:
8+
- 'v*'
9+
pull_request:
10+
branches:
11+
- 'main'
12+
paths:
13+
- 'Dockerfile'
14+
- '.dockerignore'
15+
16+
env:
17+
REGISTRY: ghcr.io
18+
IMAGE_NAME: ${{ github.repository }}
19+
20+
jobs:
21+
docker:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v3
26+
27+
- name: Set up QEMU
28+
uses: docker/setup-qemu-action@v2
29+
30+
- name: Set up Docker Buildx
31+
uses: docker/setup-buildx-action@v2
32+
33+
- name: Docker meta
34+
id: meta
35+
uses: docker/metadata-action@v4
36+
with:
37+
images: |
38+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
39+
tags: |
40+
type=ref,event=branch
41+
type=ref,event=pr
42+
type=semver,pattern={{version}}
43+
type=semver,pattern={{major}}.{{minor}}
44+
45+
- name: Login to Container Registry
46+
if: github.event_name != 'pull_request'
47+
uses: docker/login-action@v2
48+
with:
49+
registry: ${{ env.REGISTRY }}
50+
username: ${{ github.actor }}
51+
password: ${{ secrets.GITHUB_TOKEN }}
52+
53+
- name: Build and push
54+
uses: docker/build-push-action@v4
55+
with:
56+
context: .
57+
platforms: linux/amd64,linux/arm64
58+
push: ${{ github.event_name != 'pull_request' }}
59+
tags: ${{ steps.meta.outputs.tags }}
60+
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/go.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: go
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
branches:
8+
- master
9+
- main
10+
pull_request:
11+
12+
permissions:
13+
contents: read
14+
pull-requests: read
15+
16+
jobs:
17+
test:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v3
21+
- uses: actions/setup-go@v3
22+
with:
23+
go-version: 1.21
24+
- name: Test
25+
run: go test -v ./...

.github/workflows/goreleaser.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: goreleaser
33
on:
44
push:
55
tags:
6-
- '*'
6+
- 'v*'
77

88
permissions:
99
contents: write

.github/workflows/lint.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: lint
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
14+
golangci-lint:
15+
name: golangci-lint
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v3
19+
- uses: actions/setup-go@v4
20+
with:
21+
go-version: '1.21'
22+
cache: false
23+
- name: golangci-lint
24+
uses: golangci/golangci-lint-action@v3
25+
with:
26+
version: v1.53
27+
28+
conventional-commits:
29+
name: conventional-commits
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v3
33+
- uses: webiny/action-conventional-commits@v1.1.0

Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM golang:1.21-alpine AS build
2+
WORKDIR /app
3+
COPY go.mod go.sum ./
4+
RUN go mod download -x
5+
COPY . ./
6+
RUN CGO_ENABLED=0 go build -trimpath -o /bin/ksei-exporter ./exporter
7+
RUN CGO_ENABLED=0 go build -trimpath -o /bin/wei ./wei
8+
9+
FROM alpine:edge
10+
RUN apk add -U curl ca-certificates && update-ca-certificates
11+
COPY --from=build /bin/ksei-exporter /bin/ksei-exporter
12+
COPY --from=build /bin/wei /bin/wei
13+
CMD [ "/bin/ksei-exporter" ]

exporter/main.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@ import (
1616
)
1717

1818
type Config struct {
19-
Bind string `envconfig:"bind" default:"0.0.0.0:8080"`
20-
Router struct {
19+
BindHost string `envconfig:"bind_host" default:"0.0.0.0"`
20+
BindPort int `envconfig:"bind_port" default:"8080"`
21+
Router struct {
2122
URL string `envconfig:"url"`
2223
Username string `envconfig:"username"`
2324
Password string `envconfig:"password"`
2425
} `envconfig:"router"`
2526
}
2627

28+
func (c *Config) Bind() string {
29+
return fmt.Sprintf("%s:%d", c.BindHost, c.BindPort)
30+
}
31+
2732
func main() {
2833
_ = godotenv.Overload(".env")
2934

@@ -53,12 +58,12 @@ func main() {
5358
})))
5459

5560
log.Info().
56-
Str("bind", cfg.Bind).
61+
Str("bind", cfg.Bind()).
5762
Str("url", cfg.Router.URL).
5863
Str("user", cfg.Router.Username).
5964
Msg("starting metrics exporter server")
6065

61-
if err := e.Start(cfg.Bind); err != nil {
66+
if err := e.Start(cfg.Bind()); err != nil {
6267
fmt.Println()
6368
fmt.Println(err)
6469
os.Exit(1)

0 commit comments

Comments
 (0)