Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:

jobs:
lint:
if: false # disable linting for infobloxopen/migrate
name: lint
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 0 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ linters:
- unparam
- nakedret
- prealloc
- revive
#- gosec
linters-settings:
misspell:
locale: US
revive:
rules:
- name: redundant-build-tag
issues:
max-same-issues: 0
max-issues-per-linter: 0
Expand Down
13 changes: 6 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM golang:1.24-alpine3.21 AS builder
FROM golang:1.24-alpine AS builder
ARG VERSION

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

WORKDIR /go/src/github.com/golang-migrate/migrate
WORKDIR /go/src/github.com/infobloxopen/migrate

ENV GO111MODULE=on

Expand All @@ -15,12 +15,11 @@ COPY . ./

RUN make build-docker

FROM alpine:3.21
FROM gcr.io/distroless/static:nonroot

RUN apk add --no-cache ca-certificates

COPY --from=builder /go/src/github.com/golang-migrate/migrate/build/migrate.linux-386 /usr/local/bin/migrate
RUN ln -s /usr/local/bin/migrate /migrate
COPY --from=builder /go/src/github.com/infobloxopen/migrate/cmd/migrate/config /cli/config/
COPY --from=builder /go/src/github.com/infobloxopen/migrate/build/migrate.linux-386 /migrate
COPY --from=builder /etc/ssl/certs/ /etc/ssl/certs/

ENTRYPOINT ["migrate"]
CMD ["--help"]
63 changes: 63 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

// This library defines the isPrBuild, prepareBuild and finalizeBuild methods
@Library('jenkins.shared.library') _

pipeline {
agent {
label 'ubuntu_docker_label'
}
tools {
go "Go 1.24.2"
}
options {
checkoutToSubdirectory('src/github.com/infobloxopen/migrate')
}
environment {
GOPATH = "$WORKSPACE"
DIRECTORY = "src/github.com/infobloxopen/migrate"
}

stages {
stage("Setup") {
steps {
// prepareBuild is one of the Secure CICD helper methods
prepareBuild()
}
}
stage("Unit Tests") {
steps {
dir("$DIRECTORY") {
// sh "make test"
}
}
}
stage("Build Image") {
steps {
withDockerRegistry([credentialsId: "${env.JENKINS_DOCKER_CRED_ID}", url: ""]) {
dir("$DIRECTORY") {
sh "make build"
}
}
}
}
}
post {
success {
// finalizeBuild is one of the Secure CICD helper methods
dir("$DIRECTORY") {
finalizeBuild(
sh(
script: 'make list-of-images',
returnStdout: true
)
)
}
}
cleanup {
dir("$DIRECTORY") {
sh "make clean || true"
}
cleanWs()
}
}
}
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
SOURCE ?= file go_bindata github github_ee bitbucket aws_s3 google_cloud_storage godoc_vfs gitlab
DATABASE ?= postgres mysql redshift cassandra spanner cockroachdb yugabytedb clickhouse mongodb sqlserver firebird neo4j pgx pgx5 rqlite
DATABASE_TEST ?= $(DATABASE) sqlite sqlite3 sqlcipher
VERSION ?= $(shell git describe --tags 2>/dev/null | cut -c 2-)
BUILD_NUMBER ?= 0
VERSION ?= $(shell git describe --tags --long --dirty=-unsupported 2>/dev/null | cut -c 2-)-j$(BUILD_NUMBER)
TEST_FLAGS ?=
REPO_OWNER ?= $(shell cd .. && basename "$$(pwd)")
COVERAGE_DIR ?= .coverage
Expand All @@ -24,6 +25,14 @@ build-cli: clean
cd ./cli/build && shasum -a 256 * > sha256sum.txt
cat ./cli/build/sha256sum.txt

docker-push:
docker push infoblox/migrate:$(VERSION)

show-image-version:
echo $(VERSION)

list-of-images:
@echo "infoblox/migrate:$(VERSION)"

clean:
-rm -r ./cli/build
Expand Down Expand Up @@ -117,4 +126,3 @@ endef

SHELL = /bin/sh
RAND = $(shell echo $$RANDOM)

1 change: 1 addition & 0 deletions cmd/migrate/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
migrate
42 changes: 42 additions & 0 deletions cmd/migrate/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import "github.com/spf13/pflag"

const (
// configuration defaults support local development (i.e. "go run ...")
defaultDatabaseDSN = ""
defaultDatabaseDriver = "postgres"
defaultDatabaseAddress = "0.0.0.0:5432"
defaultDatabaseName = ""
defaultDatabaseUser = "postgres"
defaultDatabasePassword = "postgres"
defaultDatabaseSSL = "disable"
defaultConfigDirectory = "/cli/config"
)

var (
// define flag overrides
flagHelp = pflag.Bool("help", false, "Print usage")
flagVersion = pflag.String("version", Version, "Print version")
flagLoggingVerbose = pflag.Bool("verbose", true, "Print verbose logging")
flagPrefetch = pflag.Uint("prefetch", 10, "Number of migrations to load in advance before executing")
flaglockTimeout = pflag.Uint("lock-timeout", 15, "Allow N seconds to acquire database lock")

flagDatabaseDSN = pflag.String("database.dsn", defaultDatabaseDSN, "database connection string")
flagDatabaseDriver = pflag.String("database.driver", defaultDatabaseDriver, "database driver")
flagDatabaseAddress = pflag.String("database.address", defaultDatabaseAddress, "address of the database")
flagDatabaseName = pflag.String("database.name", defaultDatabaseName, "name of the database")
flagDatabaseUser = pflag.String("database.user", defaultDatabaseUser, "database username")
flagDatabasePassword = pflag.String("database.password", defaultDatabasePassword, "database password")
flagDatabaseSSL = pflag.String("database.ssl", defaultDatabaseSSL, "database ssl mode")

flagSource = pflag.String("source", "", "Location of the migrations (driver://url)")
flagPath = pflag.String("path", "", "Shorthand for -source=file://path")

flagConfigDirectory = pflag.String("config.source", defaultConfigDirectory, "directory of the configuration file")
flagConfigFile = pflag.String("config.file", "", "configuration file name without extension")

// goto command flags
flagDirty = pflag.Bool("force-dirty-handling", false, "force the handling of dirty database state")
flagMountPath = pflag.String("cache-dir", "", "path to the cache-dir which is used to copy the migration files")
)
14 changes: 14 additions & 0 deletions cmd/migrate/config/defaults.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
help: false
version: false
verbose: true
prefetch: 10
lockTimeout: 15
path: "/atlas-migrations/migrations"
#source: "file:///atlas-migrations/migrations"
database:
driver: postgres
address: postgres:5432
name: app_db
user: postgres
password: postgres
ssl: disable
35 changes: 34 additions & 1 deletion cmd/migrate/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
package main

import "github.com/golang-migrate/migrate/v4/internal/cli"
import (
"log"
"strings"

"github.com/golang-migrate/migrate/v4/internal/cli"
"github.com/infobloxopen/hotload"

Check failure on line 8 in cmd/migrate/main.go

View workflow job for this annotation

GitHub Actions / test (1.24.x)

no required module provides package github.com/infobloxopen/hotload; to add it:

Check failure on line 8 in cmd/migrate/main.go

View workflow job for this annotation

GitHub Actions / test (1.25.x)

no required module provides package github.com/infobloxopen/hotload; to add it:
_ "github.com/infobloxopen/hotload/fsnotify"

Check failure on line 9 in cmd/migrate/main.go

View workflow job for this annotation

GitHub Actions / test (1.24.x)

no required module provides package github.com/infobloxopen/hotload/fsnotify; to add it:

Check failure on line 9 in cmd/migrate/main.go

View workflow job for this annotation

GitHub Actions / test (1.25.x)

no required module provides package github.com/infobloxopen/hotload/fsnotify; to add it:
"github.com/jackc/pgx/v4/stdlib"
"github.com/lib/pq"
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)

func init() {
pflag.Parse()
viper.BindPFlags(pflag.CommandLine)
viper.AutomaticEnv()
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AddConfigPath(viper.GetString("config.source"))
if viper.GetString("config.file") != "" {
viper.SetConfigName(viper.GetString("config.file"))
if err := viper.ReadInConfig(); err != nil {
log.Fatalf("cannot load configuration: %v", err)
}
}
// logrus formatter
customFormatter := new(logrus.JSONFormatter)
logrus.SetFormatter(customFormatter)

hotload.RegisterSQLDriver("pgx", stdlib.GetDefaultDriver())
hotload.RegisterSQLDriver("postgres", pq.Driver{})
hotload.RegisterSQLDriver("postgresql", pq.Driver{})
}

func main() {
cli.Main(Version)
Expand Down
2 changes: 1 addition & 1 deletion docker-deploy.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin && \
docker build --build-arg VERSION="$TRAVIS_TAG" . -t migrate/migrate -t migrate/migrate:"$TRAVIS_TAG" && \
docker build --pull --build-arg VERSION="$TRAVIS_TAG" . -t migrate/migrate -t migrate/migrate:"$TRAVIS_TAG" && \
docker push migrate/migrate:"$TRAVIS_TAG" && docker push migrate/migrate
2 changes: 1 addition & 1 deletion internal/cli/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cli

import (
"fmt"
logpkg "log"
logpkg "github.com/sirupsen/logrus"
"os"
)

Expand Down
Loading
Loading