add dockerization Fix #23

Signed-off-by: Alexandre MARRE <me@itsalex.fr>
This commit is contained in:
ItsAlex 2018-05-08 21:13:53 +02:00 committed by Alexandre MARRE
parent 81e9fff605
commit fb7bb4f87a
No known key found for this signature in database
GPG Key ID: D13067073B9A98A9
5 changed files with 55 additions and 0 deletions

13
.dockerignore Normal file
View File

@ -0,0 +1,13 @@
# Project
FAQ.md
README.md
LICENSE
Makefile
.gitignore
.travis.yml
CONTRIBUTING.md
MIGRATIONS.md
docker-deploy.sh
# Golang
testing

View File

@ -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

25
Dockerfile Normal file
View File

@ -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"]

View File

@ -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

5
docker-deploy.sh Executable file
View File

@ -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"