Skip to content

Commit 1c7fe29

Browse files
authoredJul 24, 2020
Merge pull request #26 from dsrhub/zz/refactor-migration
Refactor migrations
2 parents 75e4654 + e4a30f6 commit 1c7fe29

10 files changed

+114
-146
lines changed
 

‎Dockerfile

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
1-
# ARG UTASK_IMAGE=ovhcom/utask:v1.8.1
1+
# ARG UTASK_IMAGE=ovhcom/utask:v1.8.3
2+
# TODO: upgrade to ovhcom/utask:v1.8.3 when it's ready
23
ARG UTASK_IMAGE=zhouzhuojie/utask:beta-with-middleware
34

5+
6+
7+
48
FROM ${UTASK_IMAGE} AS builder
59
WORKDIR /go/src/github.com/ovh/utask
610
COPY init init
711
COPY plugins plugins
812
COPY pkg /go/src/github.com/dsrhub/dsrhub/pkg
913
RUN make
1014

15+
16+
17+
1118
FROM ${UTASK_IMAGE}
12-
COPY templates /app/templates
1319
COPY --from=builder /go/src/github.com/ovh/utask/plugins /app/plugins
1420
COPY --from=builder /go/src/github.com/ovh/utask/init /app/init
1521
COPY --from=builder /go/src/github.com/ovh/utask/utask /app/utask
22+
COPY --from=builder /go/src/github.com/ovh/utask/sql /app/sql
23+
RUN go get -v github.com/rubenv/sql-migrate/...
24+
COPY ./templates /app/templates
25+
COPY ./dbconfig.yml /app/dbconfig.yml
1626
RUN chmod +x /app/utask
27+
WORKDIR /app

‎Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ docker_functional_test:
2525
docker-compose build
2626
docker-compose up --no-start
2727
for f in ./mocks/openmock_templates/*.yaml; do docker cp $$f dsrhub_openmock:/data/templates/; done
28-
for f in ./sql/schema.sql; do docker cp $$f dsrhub_db:/docker-entrypoint-initdb.d/; done
2928
for f in ./templates/*.yaml; do docker cp $$f dsrhub_utask:/app/templates/; done
3029
for f in ./functional_test/*.yaml; do docker cp $$f dsrhub_functional_test:/var/local/; done
3130
docker-compose up -d

‎dbconfig.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
postgres:
2+
dialect: postgres
3+
datasource: ${CFG_DATABASE}
4+
dir: /app/sql/migrations

‎docker-compose.example.yaml

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
version: "2.4"
22
services:
3-
dsrhub:
3+
utask:
44
image: dsrhub/dsrhub
5-
container_name: dsrhub_dsrhub
5+
container_name: dsrhub_utask
66
restart: on-failure
77
command: ["/wait-for-it.sh", "db:5432", "--", "/app/utask"]
88
environment:
99
DEBUG: 'true'
1010
DEV: 'true'
1111
CONFIGURATION_FROM: 'env:CFG'
12-
CFG_DATABASE: 'postgres://user:pass@db/dsrhub?sslmode=disable'
12+
CFG_DATABASE: 'postgres://user:pass@db/utask?sslmode=disable'
1313
CFG_UTASK_CFG: '{"admin_usernames":["admin"],"application_name":"µTask"}'
1414
CFG_BASIC_AUTH: '{"admin":"1234","resolver":"3456","regular":"5678"}'
1515
CFG_ENCRYPTION_KEY: '{"identifier":"storage","cipher":"aes-gcm","timestamp":1535627466,"key":"e5f45aef9f072e91f735547be63f3434e6de49695b178e3868b23b0e32269800"}'
@@ -19,6 +19,17 @@ services:
1919
- "./templates:/app/templates"
2020
depends_on:
2121
- db
22+
- migrate
23+
24+
migrate:
25+
image: dsrhub/dsrhub
26+
container_name: dsrhub_migrate
27+
command: ["/wait-for-it.sh", "db:5432", "--", "sql-migrate", "up", "-env", "postgres"]
28+
environment:
29+
CFG_DATABASE: 'postgres://user:pass@db/utask?sslmode=disable'
30+
restart: on-failure
31+
depends_on:
32+
- db
2233

2334
db:
2435
image: postgres:9.5.3
@@ -27,6 +38,4 @@ services:
2738
environment:
2839
POSTGRES_USER: user
2940
POSTGRES_PASSWORD: pass
30-
POSTGRES_DB: dsrhub
31-
volumes:
32-
- "./sql:/docker-entrypoint-initdb.d"
41+
POSTGRES_DB: utask

‎docker-compose.yaml

+11-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ services:
1919
- "./templates:/app/templates"
2020
depends_on:
2121
- db
22+
- migrate
23+
24+
migrate:
25+
build: .
26+
container_name: dsrhub_migrate
27+
command: ["/wait-for-it.sh", "db:5432", "--", "sql-migrate", "up", "-env", "postgres"]
28+
environment:
29+
CFG_DATABASE: 'postgres://user:pass@db/utask?sslmode=disable'
30+
restart: on-failure
31+
depends_on:
32+
- db
2233

2334
db:
2435
image: postgres:9.5.3
@@ -28,8 +39,6 @@ services:
2839
POSTGRES_USER: user
2940
POSTGRES_PASSWORD: pass
3041
POSTGRES_DB: utask
31-
volumes:
32-
- "./sql:/docker-entrypoint-initdb.d"
3342

3443
openmock:
3544
build: ./mocks

‎mocks/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.14
44

55
require (
66
github.com/checkr/openmock v0.3.2
7-
github.com/dsrhub/dsrhub v0.0.5
7+
github.com/dsrhub/dsrhub v0.0.8
88
github.com/go-openapi/loads v0.19.5
99
github.com/golang/protobuf v1.4.2
1010
github.com/jessevdk/go-flags v1.4.0

‎mocks/go.sum

+70-26
Large diffs are not rendered by default.

‎pkg/.gitkeep

Whitespace-only changes.

‎pkg/main.go

-1
This file was deleted.

‎sql/schema.sql

-107
This file was deleted.

0 commit comments

Comments
 (0)