Skip to content

Commit

Permalink
Introduce docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
erickskrauch committed Nov 17, 2023
1 parent 87aa380 commit 9cad666
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
25 changes: 22 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: Build

on: [push]
on:
push:
branches:
- master

env:
go_version: 1.21

jobs:
build:
Expand All @@ -9,14 +15,27 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Setup Go 1.21
- name: Setup Go ${{ env.go_version }}
uses: actions/setup-go@v4
with:
go-version: 1.21
go-version: ${{ env.go_version }}
cache-dependency-path: go.sum

- name: Install dependencies
run: go get .

- name: Build
run: go build ./...

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
with:
push: true
tags: ghcr.io/${{ github.repository }}:latest
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# syntax=docker/dockerfile:1

FROM golang:1.21 AS builder

COPY . /build
WORKDIR /build
RUN go mod download

RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 \
go build \
-trimpath \
-ldflags="-w -s" \
-o app \
main.go

FROM scratch

COPY --from=builder /build/app /root/app

ENTRYPOINT ["/root/app"]
EXPOSE 8080
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func main() {
viper.AutomaticEnv()
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))

viper.SetDefault("http.host", "localhost")
viper.SetDefault("http.host", "0.0.0.0")
viper.SetDefault("http.port", 8080)

viper.SetDefault("mysql.user", "root")
Expand Down

0 comments on commit 9cad666

Please sign in to comment.