Introduce docker build

This commit is contained in:
ErickSkrauch 2023-11-17 05:39:45 +01:00
parent 87aa380a9d
commit 9cad666e9f
No known key found for this signature in database
GPG Key ID: 669339FCBB30EE0E
3 changed files with 44 additions and 4 deletions

View File

@ -1,6 +1,12 @@
name: Build
on: [push]
on:
push:
branches:
- master
env:
go_version: 1.21
jobs:
build:
@ -9,10 +15,10 @@ 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
@ -20,3 +26,16 @@ jobs:
- 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
Dockerfile Normal file
View File

@ -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

View File

@ -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")