Skip to content

Commit

Permalink
Merge pull request #6 from cropalato/docker-build
Browse files Browse the repository at this point in the history
Docker build
  • Loading branch information
cropalato authored Aug 27, 2024
2 parents 248d9ff + e9c7772 commit 6f26236
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 8 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/docker_go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: ci

on:
push:
branches:
- main
tags:
- "v*.*.*"

jobs:
build:
runs-on: ubuntu-latest
steps:
-
name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
cropalato/MergeSentinel
# generate Docker tags based on the following events/attributes
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
-
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKER_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Build and push
uses: docker/build-push-action@v6
with:
platforms: linux/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# syntax=docker/dockerfile:1

FROM golang:1.23 AS build-stage

# Set destination for COPY
WORKDIR /app

# Download Go modules
COPY go.mod go.sum ./
RUN go mod download

# Copy the source code. Note the slash at the end, as explained in
# https://docs.docker.com/reference/dockerfile/#copy
COPY . ./

# Build
RUN CGO_ENABLED=0 GOOS=linux go build -o bin ./...

# Deploy the application binary into a lean image
FROM gcr.io/distroless/base-debian11 AS build-release-stage

WORKDIR /

COPY --from=build-stage /app/bin/MergeSentinel /MergeSentinel

EXPOSE 8080

USER nonroot:nonroot

# Run
ENTRYPOINT ["/MergeSentinel"]
6 changes: 3 additions & 3 deletions cmd/MergeSentinel/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ import (
"github.com/gorilla/mux"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/cropalato/gitlabce-approval/internal/varenv"
"github.com/cropalato/gitlabce-approval/internal/webservices"
"github.com/cropalato/MergeSentinel/internal/varenv"
"github.com/cropalato/MergeSentinel/internal/webservices"
)

func main() {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
listen := flag.String("listen", varenv.LookupEnvOrString("GLCE_APPROV_LISTEN", ":8080"), "IP and port used by the service. format: '[<ip>]:<port>'. default: ':8080'")
// the dafault password is 'admin'. ypu can use create a new one using
// python -c 'import bcrypt; print(bcrypt.hashpw(b"PASSWORD", bcrypt.gensalt(rounds=15)).decode("ascii"))'
cfg_path := flag.String("cfg_path", varenv.LookupEnvOrString("GLCE_CONF_PATH", ""), "config file path")
cfg_path := flag.String("cfg_path", varenv.LookupEnvOrString("GLCE_CONF_PATH", "msentinel.json"), "config file path")
debug := flag.Bool("debug", false, "sets log level to debug")
flag.Parse()

Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/cropalato/gitlabce-approval
module github.com/cropalato/MergeSentinel

go 1.23.0

Expand All @@ -21,7 +21,6 @@ require (
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
Expand Down
2 changes: 1 addition & 1 deletion internal/webservices/webservices.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"strings"
"time"

"github.com/cropalato/gitlabce-approval/internal/conf"
"github.com/cropalato/MergeSentinel/internal/conf"
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
"github.com/rs/zerolog/log"
Expand Down

0 comments on commit 6f26236

Please sign in to comment.