diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ae5fd8f..d892b63 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c7f7a0f --- /dev/null +++ b/Dockerfile @@ -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 diff --git a/main.go b/main.go index 3c08a26..15e6ade 100644 --- a/main.go +++ b/main.go @@ -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")