From fb7bb4f87a896c8f45870d533f7c54cb5fb98530 Mon Sep 17 00:00:00 2001 From: ItsAlex Date: Tue, 8 May 2018 21:13:53 +0200 Subject: [PATCH] add dockerization Fix #23 Signed-off-by: Alexandre MARRE --- .dockerignore | 13 +++++++++++++ .travis.yml | 6 ++++++ Dockerfile | 25 +++++++++++++++++++++++++ README.md | 6 ++++++ docker-deploy.sh | 5 +++++ 5 files changed, 55 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100755 docker-deploy.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..df33687 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +# Project +FAQ.md +README.md +LICENSE +Makefile +.gitignore +.travis.yml +CONTRIBUTING.md +MIGRATIONS.md +docker-deploy.sh + +# Golang +testing diff --git a/.travis.yml b/.travis.yml index b360822..59e563d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -68,3 +68,9 @@ deploy: go: "1.10" repo: golang-migrate/migrate tags: true + - provider: script + script: ./docker-deploy.sh + on: + go: "1.10" + repo: golang-migrate/migrate + tags: true diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bc8d60c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM golang:1.10-alpine3.7 AS downloader + +RUN apk add --no-cache git gcc musl-dev + +WORKDIR /go/src/github.com/golang-migrate/migrate + +COPY *.go ./ +COPY cli ./cli +COPY database ./database +COPY source ./source + +RUN go get -v ./... && \ + go get -u github.com/fsouza/fake-gcs-server/fakestorage && \ + go get -u github.com/kshvakov/clickhouse && \ + GOOS=linux GOARCH=386 go build -a -o build/migrate.linux-386 -ldflags='-X main.Version=$(VERSION)' -tags '$(DATABASE) $(SOURCE)' ./cli + +FROM alpine:3.7 + +RUN apk add --no-cache ca-certificates + +COPY --from=downloader /go/src/github.com/golang-migrate/migrate/build/migrate.linux-386 /migrate +RUN chmod u+x /migrate + +ENTRYPOINT ["/migrate"] +CMD ["--help"] \ No newline at end of file diff --git a/README.md b/README.md index e0fdf08..f422a4c 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,12 @@ $ brew install migrate --with-postgres $ migrate -database postgres://localhost:5432/database up 2 ``` +### Docker usage + +``` +$ docker run -v {{ migration dir }}:/migrations --network host migrate/migrate + -path=/migrations/ -database postgres://localhost:5432/database up 2 +``` ## Use in your Go project diff --git a/docker-deploy.sh b/docker-deploy.sh new file mode 100755 index 0000000..8273b41 --- /dev/null +++ b/docker-deploy.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin && \ +docker build . -t migrate/migrate:"$TRAVIS_TAG" && \ +docker push migrate/migrate:"$TRAVIS_TAG"