Skip to content

Commit

Permalink
Merge pull request #1 from chickenzord/feat/docker
Browse files Browse the repository at this point in the history
feat: Dockerize
  • Loading branch information
akhy committed Jan 12, 2024
2 parents f423ff4 + ddce526 commit 7177a63
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 5 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Docker

on:
push:
branches:
- 'main'
tags:
- 'v*'
pull_request:
branches:
- 'main'
paths:
- 'Dockerfile'
- '.dockerignore'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Login to Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
25 changes: 25 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: go

on:
push:
tags:
- v*
branches:
- master
- main
pull_request:

permissions:
contents: read
pull-requests: read

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.21
- name: Test
run: go test -v ./...
2 changes: 1 addition & 1 deletion .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: goreleaser
on:
push:
tags:
- '*'
- 'v*'

permissions:
contents: write
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: lint

on:
push:
branches:
- main
pull_request:

permissions:
contents: read

jobs:

golangci-lint:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.21'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.53

conventional-commits:
name: conventional-commits
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: webiny/action-conventional-commits@v1.1.0
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM golang:1.21-alpine AS build
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download -x
COPY . ./
RUN CGO_ENABLED=0 go build -trimpath -o /bin/ksei-exporter ./exporter
RUN CGO_ENABLED=0 go build -trimpath -o /bin/wei ./wei

FROM alpine:edge
RUN apk add -U curl ca-certificates && update-ca-certificates
COPY --from=build /bin/ksei-exporter /bin/ksei-exporter
COPY --from=build /bin/wei /bin/wei
CMD [ "/bin/ksei-exporter" ]
13 changes: 9 additions & 4 deletions exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@ import (
)

type Config struct {
Bind string `envconfig:"bind" default:"0.0.0.0:8080"`
Router struct {
BindHost string `envconfig:"bind_host" default:"0.0.0.0"`
BindPort int `envconfig:"bind_port" default:"8080"`
Router struct {
URL string `envconfig:"url"`
Username string `envconfig:"username"`
Password string `envconfig:"password"`
} `envconfig:"router"`
}

func (c *Config) Bind() string {
return fmt.Sprintf("%s:%d", c.BindHost, c.BindPort)
}

func main() {
_ = godotenv.Overload(".env")

Expand Down Expand Up @@ -53,12 +58,12 @@ func main() {
})))

log.Info().
Str("bind", cfg.Bind).
Str("bind", cfg.Bind()).
Str("url", cfg.Router.URL).
Str("user", cfg.Router.Username).
Msg("starting metrics exporter server")

if err := e.Start(cfg.Bind); err != nil {
if err := e.Start(cfg.Bind()); err != nil {
fmt.Println()
fmt.Println(err)
os.Exit(1)
Expand Down

0 comments on commit 7177a63

Please sign in to comment.