Skip to content

Commit 1d9eeda

Browse files
author
Krzysztof Wilczyński
authored
APPSRE-6175: Update instance expiration management (#46)
Signed-off-by: Krzysztof Wilczyński <[email protected]>
1 parent f1a0491 commit 1d9eeda

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+4273
-881
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.git

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ __debug_*
1717
# Output of the go coverage tool, specifically when used with LiteIDE
1818
*.out
1919

20-
test/user*
20+
test/user*
21+
22+
gabi

.gitleaks.toml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[allowlist]
2+
description = "Allow Go test files"
3+
files = [
4+
'''^(.*?)_test\.go'''
5+
]

Dockerfile

+21-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
1-
FROM quay.io/app-sre/golang:1.18 as builder
1+
FROM quay.io/app-sre/golang:1.19 as builder
2+
3+
ENV GOGC=off
4+
ENV CGO_ENABLED=0
5+
26
WORKDIR /build
3-
COPY . .
4-
RUN make clean linux
7+
8+
COPY go.mod go.sum ./
9+
10+
RUN set -eux && \
11+
go mod download
12+
13+
COPY . ./
14+
15+
RUN set -eux && \
16+
go build -ldflags '-s -w' -o gabi cmd/gabi/main.go
517

618
FROM registry.access.redhat.com/ubi8/ubi-minimal
719

8-
EXPOSE 8080
920
ENV DB_DRIVER=pgx
1021
ENV DB_HOST=127.0.0.1
1122
ENV DB_PORT=5432
1223
ENV DB_USER=postgres
1324
ENV DB_PASS=postgres
14-
ENV DB_NAME=mydb
25+
ENV DB_NAME=main
1526
ENV DB_WRITE=false
1627

28+
EXPOSE 8080
29+
30+
USER 1001
31+
1732
COPY --from=builder /build/gabi .
33+
1834
CMD ["./gabi"]

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
all: build
44

55
build:
6-
go build -o gabi cmd/gabi/main.go
6+
go build -o gabi cmd/gabi/main.go
77

88
linux:
9-
CGO_ENABLED=0 GOOS=linux go build -a -tags netgo -ldflags '-w' -o gabi cmd/gabi/main.go
9+
CGO_ENABLED=0 GOOS=linux go build -ldflags '-s -w' -o gabi cmd/gabi/main.go
1010

1111
clean:
1212
rm -f gabi
1313

1414
test:
15-
go test -count=1 -v -timeout 300s ./...
15+
go test ./...
1616

1717
docker-build:
1818
$(BUILD_CMD) -t ${IMG} -f Dockerfile .

build_deploy.sh

+22-14
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

3-
# AppSRE team CD
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
46

5-
set -exv
7+
export PATH="/opt/go/1.19.5/bin:${PATH}"
68

79
BASE_IMG="gabi"
810
QUAY_IMAGE="quay.io/app-sre/${BASE_IMG}"
911
IMG="${BASE_IMG}:latest"
1012

11-
GIT_HASH=`git rev-parse --short=7 HEAD`
13+
readonly BASE_IMG QUAY_IMAGE IMG
1214

13-
# build the image
14-
docker login quay.io -u ${QUAY_USER} -p ${QUAY_TOKEN}
15+
GIT_HASH=$(git rev-parse --short=7 HEAD)
1516

16-
BUILD_CMD="docker build" IMG="$IMG" make docker-build
17+
{
18+
set +x
19+
docker login quay.io -u "${QUAY_USER}" -p "${QUAY_TOKEN}"
20+
}
1721

18-
# push the image to quay
19-
skopeo copy --dest-creds "${QUAY_USER}:${QUAY_TOKEN}" \
20-
"docker-daemon:${IMG}" \
21-
"docker://${QUAY_IMAGE}:latest"
22+
BUILD_CMD="docker build" IMG="${IMG}" make docker-build
2223

23-
skopeo copy --dest-creds "${QUAY_USER}:${QUAY_TOKEN}" \
24-
"docker-daemon:${IMG}" \
25-
"docker://${QUAY_IMAGE}:${GIT_HASH}"
24+
{
25+
set +x
26+
skopeo copy --dest-creds "${QUAY_USER}:${QUAY_TOKEN}" \
27+
"docker-daemon:${IMG}" \
28+
"docker://${QUAY_IMAGE}:latest"
29+
30+
skopeo copy --dest-creds "${QUAY_USER}:${QUAY_TOKEN}" \
31+
"docker-daemon:${IMG}" \
32+
"docker://${QUAY_IMAGE}:${GIT_HASH}"
33+
}

cmd/gabi/main.go

+8-10
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,19 @@ package main
33
import (
44
"log"
55

6-
"go.uber.org/zap"
7-
8-
gabi "github.com/app-sre/gabi/pkg"
96
"github.com/app-sre/gabi/pkg/cmd"
7+
"go.uber.org/zap"
108
)
119

1210
func main() {
13-
logger, err := zap.NewDevelopment() // NewProduction
11+
l, err := zap.NewDevelopment()
1412
if err != nil {
15-
log.Fatalf("can't initialize zap logger: %v", err)
13+
log.Fatalf("Unable to initialize Zap logger: %s", err)
1614
}
17-
defer logger.Sync()
15+
defer func() { _ = l.Sync() }()
1816

19-
loggerS := logger.Sugar()
20-
loggerS.Info("Starting gabi server version " + gabi.Version)
21-
22-
cmd.Run(loggerS)
17+
logger := l.Sugar()
18+
if err := cmd.Run(logger); err != nil {
19+
logger.Fatalf("Unable to start GABI: %s", err)
20+
}
2321
}

go.mod

+22-16
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
module github.com/app-sre/gabi
22

3-
go 1.18
3+
go 1.19
44

55
require (
6+
github.com/DATA-DOG/go-sqlmock v1.5.0
67
github.com/etherlabsio/healthcheck/v2 v2.0.0
7-
github.com/go-sql-driver/mysql v1.6.0
8+
github.com/go-sql-driver/mysql v1.7.0
89
github.com/gorilla/handlers v1.5.1
910
github.com/gorilla/mux v1.8.0
10-
github.com/jackc/pgx/v4 v4.11.0
11+
github.com/jackc/pgx/v4 v4.17.2
12+
github.com/justinas/alice v1.2.0
1113
github.com/orlangure/gnomock v0.24.0
1214
github.com/stretchr/testify v1.8.1
13-
go.uber.org/zap v1.23.0
15+
go.uber.org/zap v1.24.0
1416
)
1517

1618
require (
@@ -21,28 +23,32 @@ require (
2123
github.com/docker/docker v20.10.21+incompatible // indirect
2224
github.com/docker/go-connections v0.4.0 // indirect
2325
github.com/docker/go-units v0.4.0 // indirect
24-
github.com/felixge/httpsnoop v1.0.1 // indirect
26+
github.com/felixge/httpsnoop v1.0.3 // indirect
2527
github.com/gogo/protobuf v1.3.2 // indirect
28+
github.com/google/go-cmp v0.5.9 // indirect
2629
github.com/google/uuid v1.3.0 // indirect
2730
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
28-
github.com/jackc/pgconn v1.8.1 // indirect
31+
github.com/jackc/pgconn v1.13.0 // indirect
2932
github.com/jackc/pgio v1.0.0 // indirect
3033
github.com/jackc/pgpassfile v1.0.0 // indirect
31-
github.com/jackc/pgproto3/v2 v2.0.6 // indirect
32-
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
33-
github.com/jackc/pgtype v1.7.0 // indirect
34+
github.com/jackc/pgproto3/v2 v2.3.1 // indirect
35+
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
36+
github.com/jackc/pgtype v1.12.0 // indirect
37+
github.com/kr/pretty v0.3.0 // indirect
3438
github.com/lib/pq v1.10.7 // indirect
3539
github.com/opencontainers/go-digest v1.0.0 // indirect
3640
github.com/opencontainers/image-spec v1.0.2 // indirect
3741
github.com/pkg/errors v0.9.1 // indirect
3842
github.com/pmezard/go-difflib v1.0.0 // indirect
39-
github.com/sirupsen/logrus v1.8.1 // indirect
40-
go.uber.org/atomic v1.9.0 // indirect
41-
go.uber.org/multierr v1.7.0 // indirect
42-
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
43-
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
43+
github.com/rogpeppe/go-internal v1.9.0 // indirect
44+
github.com/sirupsen/logrus v1.9.0 // indirect
45+
go.uber.org/atomic v1.10.0 // indirect
46+
go.uber.org/multierr v1.9.0 // indirect
47+
golang.org/x/crypto v0.5.0 // indirect
48+
golang.org/x/net v0.5.0 // indirect
4449
golang.org/x/sync v0.1.0 // indirect
45-
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
46-
golang.org/x/text v0.3.7 // indirect
50+
golang.org/x/sys v0.4.0 // indirect
51+
golang.org/x/text v0.6.0 // indirect
52+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
4753
gopkg.in/yaml.v3 v3.0.1 // indirect
4854
)

0 commit comments

Comments
 (0)