Skip to content

Commit cba7809

Browse files
committed
infoblox customizations
1 parent 8b9c5f7 commit cba7809

File tree

14 files changed

+836
-53
lines changed

14 files changed

+836
-53
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66

77
jobs:
88
lint:
9+
if: false # disable linting for infobloxopen/migrate
910
name: lint
1011
runs-on: ubuntu-latest
1112
steps:

.golangci.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,10 @@ linters:
1313
- unparam
1414
- nakedret
1515
- prealloc
16-
- revive
1716
#- gosec
1817
linters-settings:
1918
misspell:
2019
locale: US
21-
revive:
22-
rules:
23-
- name: redundant-build-tag
2420
issues:
2521
max-same-issues: 0
2622
max-issues-per-linter: 0

Dockerfile

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
FROM golang:1.24-alpine3.21 AS builder
1+
FROM golang:1.24-alpine AS builder
22
ARG VERSION
33

44
RUN apk add --no-cache git gcc musl-dev make
55

6-
WORKDIR /go/src/github.com/golang-migrate/migrate
6+
WORKDIR /go/src/github.com/infobloxopen/migrate
77

88
ENV GO111MODULE=on
99

@@ -15,12 +15,11 @@ COPY . ./
1515

1616
RUN make build-docker
1717

18-
FROM alpine:3.21
18+
FROM gcr.io/distroless/static:nonroot
1919

20-
RUN apk add --no-cache ca-certificates
21-
22-
COPY --from=builder /go/src/github.com/golang-migrate/migrate/build/migrate.linux-386 /usr/local/bin/migrate
23-
RUN ln -s /usr/local/bin/migrate /migrate
20+
COPY --from=builder /go/src/github.com/infobloxopen/migrate/cmd/migrate/config /cli/config/
21+
COPY --from=builder /go/src/github.com/infobloxopen/migrate/build/migrate.linux-386 /migrate
22+
COPY --from=builder /etc/ssl/certs/ /etc/ssl/certs/
2423

2524
ENTRYPOINT ["migrate"]
2625
CMD ["--help"]

Jenkinsfile

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
// This library defines the isPrBuild, prepareBuild and finalizeBuild methods
3+
@Library('jenkins.shared.library') _
4+
5+
pipeline {
6+
agent {
7+
label 'ubuntu_docker_label'
8+
}
9+
tools {
10+
go "Go 1.24.2"
11+
}
12+
options {
13+
checkoutToSubdirectory('src/github.com/infobloxopen/migrate')
14+
}
15+
environment {
16+
GOPATH = "$WORKSPACE"
17+
DIRECTORY = "src/github.com/infobloxopen/migrate"
18+
}
19+
20+
stages {
21+
stage("Setup") {
22+
steps {
23+
// prepareBuild is one of the Secure CICD helper methods
24+
prepareBuild()
25+
}
26+
}
27+
stage("Unit Tests") {
28+
steps {
29+
dir("$DIRECTORY") {
30+
// sh "make test"
31+
}
32+
}
33+
}
34+
stage("Build Image") {
35+
steps {
36+
withDockerRegistry([credentialsId: "${env.JENKINS_DOCKER_CRED_ID}", url: ""]) {
37+
dir("$DIRECTORY") {
38+
sh "make build"
39+
}
40+
}
41+
}
42+
}
43+
}
44+
post {
45+
success {
46+
// finalizeBuild is one of the Secure CICD helper methods
47+
dir("$DIRECTORY") {
48+
finalizeBuild(
49+
sh(
50+
script: 'make list-of-images',
51+
returnStdout: true
52+
)
53+
)
54+
}
55+
}
56+
cleanup {
57+
dir("$DIRECTORY") {
58+
sh "make clean || true"
59+
}
60+
cleanWs()
61+
}
62+
}
63+
}

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
SOURCE ?= file go_bindata github github_ee bitbucket aws_s3 google_cloud_storage godoc_vfs gitlab
22
DATABASE ?= postgres mysql redshift cassandra spanner cockroachdb yugabytedb clickhouse mongodb sqlserver firebird neo4j pgx pgx5 rqlite
33
DATABASE_TEST ?= $(DATABASE) sqlite sqlite3 sqlcipher
4-
VERSION ?= $(shell git describe --tags 2>/dev/null | cut -c 2-)
4+
BUILD_NUMBER ?= 0
5+
VERSION ?= $(shell git describe --tags --long --dirty=-unsupported 2>/dev/null | cut -c 2-)-j$(BUILD_NUMBER)
56
TEST_FLAGS ?=
67
REPO_OWNER ?= $(shell cd .. && basename "$$(pwd)")
78
COVERAGE_DIR ?= .coverage
@@ -24,6 +25,14 @@ build-cli: clean
2425
cd ./cli/build && shasum -a 256 * > sha256sum.txt
2526
cat ./cli/build/sha256sum.txt
2627

28+
docker-push:
29+
docker push infoblox/migrate:$(VERSION)
30+
31+
show-image-version:
32+
echo $(VERSION)
33+
34+
list-of-images:
35+
@echo "infoblox/migrate:$(VERSION)"
2736

2837
clean:
2938
-rm -r ./cli/build
@@ -117,4 +126,3 @@ endef
117126

118127
SHELL = /bin/sh
119128
RAND = $(shell echo $$RANDOM)
120-

cmd/migrate/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
migrate

cmd/migrate/config.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package main
2+
3+
import "github.com/spf13/pflag"
4+
5+
const (
6+
// configuration defaults support local development (i.e. "go run ...")
7+
defaultDatabaseDSN = ""
8+
defaultDatabaseDriver = "postgres"
9+
defaultDatabaseAddress = "0.0.0.0:5432"
10+
defaultDatabaseName = ""
11+
defaultDatabaseUser = "postgres"
12+
defaultDatabasePassword = "postgres"
13+
defaultDatabaseSSL = "disable"
14+
defaultConfigDirectory = "/cli/config"
15+
)
16+
17+
var (
18+
// define flag overrides
19+
flagHelp = pflag.Bool("help", false, "Print usage")
20+
flagVersion = pflag.String("version", Version, "Print version")
21+
flagLoggingVerbose = pflag.Bool("verbose", true, "Print verbose logging")
22+
flagPrefetch = pflag.Uint("prefetch", 10, "Number of migrations to load in advance before executing")
23+
flaglockTimeout = pflag.Uint("lock-timeout", 15, "Allow N seconds to acquire database lock")
24+
25+
flagDatabaseDSN = pflag.String("database.dsn", defaultDatabaseDSN, "database connection string")
26+
flagDatabaseDriver = pflag.String("database.driver", defaultDatabaseDriver, "database driver")
27+
flagDatabaseAddress = pflag.String("database.address", defaultDatabaseAddress, "address of the database")
28+
flagDatabaseName = pflag.String("database.name", defaultDatabaseName, "name of the database")
29+
flagDatabaseUser = pflag.String("database.user", defaultDatabaseUser, "database username")
30+
flagDatabasePassword = pflag.String("database.password", defaultDatabasePassword, "database password")
31+
flagDatabaseSSL = pflag.String("database.ssl", defaultDatabaseSSL, "database ssl mode")
32+
33+
flagSource = pflag.String("source", "", "Location of the migrations (driver://url)")
34+
flagPath = pflag.String("path", "", "Shorthand for -source=file://path")
35+
36+
flagConfigDirectory = pflag.String("config.source", defaultConfigDirectory, "directory of the configuration file")
37+
flagConfigFile = pflag.String("config.file", "", "configuration file name without extension")
38+
39+
// goto command flags
40+
flagDirty = pflag.Bool("force-dirty-handling", false, "force the handling of dirty database state")
41+
flagMountPath = pflag.String("cache-dir", "", "path to the cache-dir which is used to copy the migration files")
42+
)

cmd/migrate/config/defaults.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
help: false
2+
version: false
3+
verbose: true
4+
prefetch: 10
5+
lockTimeout: 15
6+
path: "/atlas-migrations/migrations"
7+
#source: "file:///atlas-migrations/migrations"
8+
database:
9+
driver: postgres
10+
address: postgres:5432
11+
name: app_db
12+
user: postgres
13+
password: postgres
14+
ssl: disable

cmd/migrate/main.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
11
package main
22

3-
import "github.com/golang-migrate/migrate/v4/internal/cli"
3+
import (
4+
"log"
5+
"strings"
6+
7+
"github.com/golang-migrate/migrate/v4/internal/cli"
8+
"github.com/infobloxopen/hotload"
9+
_ "github.com/infobloxopen/hotload/fsnotify"
10+
"github.com/jackc/pgx/v4/stdlib"
11+
"github.com/lib/pq"
12+
"github.com/sirupsen/logrus"
13+
"github.com/spf13/pflag"
14+
"github.com/spf13/viper"
15+
)
16+
17+
func init() {
18+
pflag.Parse()
19+
viper.BindPFlags(pflag.CommandLine)
20+
viper.AutomaticEnv()
21+
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
22+
viper.AddConfigPath(viper.GetString("config.source"))
23+
if viper.GetString("config.file") != "" {
24+
viper.SetConfigName(viper.GetString("config.file"))
25+
if err := viper.ReadInConfig(); err != nil {
26+
log.Fatalf("cannot load configuration: %v", err)
27+
}
28+
}
29+
// logrus formatter
30+
customFormatter := new(logrus.JSONFormatter)
31+
logrus.SetFormatter(customFormatter)
32+
33+
hotload.RegisterSQLDriver("pgx", stdlib.GetDefaultDriver())
34+
hotload.RegisterSQLDriver("postgres", pq.Driver{})
35+
hotload.RegisterSQLDriver("postgresql", pq.Driver{})
36+
}
437

538
func main() {
639
cli.Main(Version)

docker-deploy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
22

33
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin && \
4-
docker build --build-arg VERSION="$TRAVIS_TAG" . -t migrate/migrate -t migrate/migrate:"$TRAVIS_TAG" && \
4+
docker build --pull --build-arg VERSION="$TRAVIS_TAG" . -t migrate/migrate -t migrate/migrate:"$TRAVIS_TAG" && \
55
docker push migrate/migrate:"$TRAVIS_TAG" && docker push migrate/migrate

0 commit comments

Comments
 (0)