Skip to content

Commit

Permalink
Merge pull request #26 from dsrhub/zz/refactor-migration
Browse files Browse the repository at this point in the history
Refactor migrations
  • Loading branch information
zhouzhuojie authored Jul 24, 2020
2 parents 75e4654 + e4a30f6 commit 1c7fe29
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 146 deletions.
15 changes: 13 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
# ARG UTASK_IMAGE=ovhcom/utask:v1.8.1
# ARG UTASK_IMAGE=ovhcom/utask:v1.8.3
# TODO: upgrade to ovhcom/utask:v1.8.3 when it's ready
ARG UTASK_IMAGE=zhouzhuojie/utask:beta-with-middleware




FROM ${UTASK_IMAGE} AS builder
WORKDIR /go/src/github.com/ovh/utask
COPY init init
COPY plugins plugins
COPY pkg /go/src/github.com/dsrhub/dsrhub/pkg
RUN make




FROM ${UTASK_IMAGE}
COPY templates /app/templates
COPY --from=builder /go/src/github.com/ovh/utask/plugins /app/plugins
COPY --from=builder /go/src/github.com/ovh/utask/init /app/init
COPY --from=builder /go/src/github.com/ovh/utask/utask /app/utask
COPY --from=builder /go/src/github.com/ovh/utask/sql /app/sql
RUN go get -v github.com/rubenv/sql-migrate/...
COPY ./templates /app/templates
COPY ./dbconfig.yml /app/dbconfig.yml
RUN chmod +x /app/utask
WORKDIR /app
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ docker_functional_test:
docker-compose build
docker-compose up --no-start
for f in ./mocks/openmock_templates/*.yaml; do docker cp $$f dsrhub_openmock:/data/templates/; done
for f in ./sql/schema.sql; do docker cp $$f dsrhub_db:/docker-entrypoint-initdb.d/; done
for f in ./templates/*.yaml; do docker cp $$f dsrhub_utask:/app/templates/; done
for f in ./functional_test/*.yaml; do docker cp $$f dsrhub_functional_test:/var/local/; done
docker-compose up -d
Expand Down
4 changes: 4 additions & 0 deletions dbconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
postgres:
dialect: postgres
datasource: ${CFG_DATABASE}
dir: /app/sql/migrations
21 changes: 15 additions & 6 deletions docker-compose.example.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
version: "2.4"
services:
dsrhub:
utask:
image: dsrhub/dsrhub
container_name: dsrhub_dsrhub
container_name: dsrhub_utask
restart: on-failure
command: ["/wait-for-it.sh", "db:5432", "--", "/app/utask"]
environment:
DEBUG: 'true'
DEV: 'true'
CONFIGURATION_FROM: 'env:CFG'
CFG_DATABASE: 'postgres://user:pass@db/dsrhub?sslmode=disable'
CFG_DATABASE: 'postgres://user:pass@db/utask?sslmode=disable'
CFG_UTASK_CFG: '{"admin_usernames":["admin"],"application_name":"µTask"}'
CFG_BASIC_AUTH: '{"admin":"1234","resolver":"3456","regular":"5678"}'
CFG_ENCRYPTION_KEY: '{"identifier":"storage","cipher":"aes-gcm","timestamp":1535627466,"key":"e5f45aef9f072e91f735547be63f3434e6de49695b178e3868b23b0e32269800"}'
Expand All @@ -19,6 +19,17 @@ services:
- "./templates:/app/templates"
depends_on:
- db
- migrate

migrate:
image: dsrhub/dsrhub
container_name: dsrhub_migrate
command: ["/wait-for-it.sh", "db:5432", "--", "sql-migrate", "up", "-env", "postgres"]
environment:
CFG_DATABASE: 'postgres://user:pass@db/utask?sslmode=disable'
restart: on-failure
depends_on:
- db

db:
image: postgres:9.5.3
Expand All @@ -27,6 +38,4 @@ services:
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: dsrhub
volumes:
- "./sql:/docker-entrypoint-initdb.d"
POSTGRES_DB: utask
13 changes: 11 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ services:
- "./templates:/app/templates"
depends_on:
- db
- migrate

migrate:
build: .
container_name: dsrhub_migrate
command: ["/wait-for-it.sh", "db:5432", "--", "sql-migrate", "up", "-env", "postgres"]
environment:
CFG_DATABASE: 'postgres://user:pass@db/utask?sslmode=disable'
restart: on-failure
depends_on:
- db

db:
image: postgres:9.5.3
Expand All @@ -28,8 +39,6 @@ services:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: utask
volumes:
- "./sql:/docker-entrypoint-initdb.d"

openmock:
build: ./mocks
Expand Down
2 changes: 1 addition & 1 deletion mocks/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.14

require (
github.com/checkr/openmock v0.3.2
github.com/dsrhub/dsrhub v0.0.5
github.com/dsrhub/dsrhub v0.0.8
github.com/go-openapi/loads v0.19.5
github.com/golang/protobuf v1.4.2
github.com/jessevdk/go-flags v1.4.0
Expand Down
96 changes: 70 additions & 26 deletions mocks/go.sum

Large diffs are not rendered by default.

Empty file added pkg/.gitkeep
Empty file.
1 change: 0 additions & 1 deletion pkg/main.go

This file was deleted.

107 changes: 0 additions & 107 deletions sql/schema.sql

This file was deleted.

0 comments on commit 1c7fe29

Please sign in to comment.