mirror of
https://github.com/elyby/accounts-profiles-endpoint.git
synced 2024-12-01 19:21:02 +05:30
Introduce docker build
This commit is contained in:
parent
87aa380a9d
commit
9cad666e9f
25
.github/workflows/build.yml
vendored
25
.github/workflows/build.yml
vendored
@ -1,6 +1,12 @@
|
|||||||
name: Build
|
name: Build
|
||||||
|
|
||||||
on: [push]
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
env:
|
||||||
|
go_version: 1.21
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@ -9,10 +15,10 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Setup Go 1.21
|
- name: Setup Go ${{ env.go_version }}
|
||||||
uses: actions/setup-go@v4
|
uses: actions/setup-go@v4
|
||||||
with:
|
with:
|
||||||
go-version: 1.21
|
go-version: ${{ env.go_version }}
|
||||||
cache-dependency-path: go.sum
|
cache-dependency-path: go.sum
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
@ -20,3 +26,16 @@ jobs:
|
|||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: go 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
21
Dockerfile
Normal 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
|
2
main.go
2
main.go
@ -20,7 +20,7 @@ func main() {
|
|||||||
viper.AutomaticEnv()
|
viper.AutomaticEnv()
|
||||||
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
||||||
|
|
||||||
viper.SetDefault("http.host", "localhost")
|
viper.SetDefault("http.host", "0.0.0.0")
|
||||||
viper.SetDefault("http.port", 8080)
|
viper.SetDefault("http.port", 8080)
|
||||||
|
|
||||||
viper.SetDefault("mysql.user", "root")
|
viper.SetDefault("mysql.user", "root")
|
||||||
|
Loading…
Reference in New Issue
Block a user