Skip to content

Commit

Permalink
Add db migration container
Browse files Browse the repository at this point in the history
  • Loading branch information
Aadesh-Baral committed Aug 28, 2022
1 parent 3a28f5f commit f05c605
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
7 changes: 4 additions & 3 deletions Dockerfile.backend
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ RUN apt-get install -y osmosis
RUN apt-get install -y python3-pip python-dev build-essential
RUN pip install mbutil

RUN curl -s https://packagecloud.io/install/repositories/golang-migrate/migrate/script.deb.sh | bash
RUN apt-get update
RUN apt-get install -y migrate

COPY backend/tilemaker-configs/config.json /
COPY backend/tilemaker-configs/process.lua /
Expand All @@ -47,8 +50,6 @@ WORKDIR /server/backend/server

RUN go build

WORKDIR /server

COPY before-after.env .

ENTRYPOINT ["/start.sh"]
WORKDIR /server
1 change: 1 addition & 0 deletions backend/server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/gin-gonic/gin v1.8.1
github.com/google/uuid v1.1.2
github.com/lib/pq v1.10.6
github.com/spf13/viper v1.12.0
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5
google.golang.org/appengine v1.6.7
Expand Down
2 changes: 2 additions & 0 deletions backend/server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
github.com/lib/pq v1.10.6 h1:jbk+ZieJ0D7EVGJYpL9QTz7/YW6UHbmdnZWYyK5cdBs=
github.com/lib/pq v1.10.6/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo=
github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
Expand Down
3 changes: 2 additions & 1 deletion backend/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (
"github.com/baato/before-after/api"
db "github.com/baato/before-after/db/sqlc"
"github.com/baato/before-after/util"
_ "github.com/lib/pq"
)

func main() {
config, err := util.LoadConfig("../../")
if err != nil {
log.Fatal("cannot load config:", err)
log.Fatal("cannot load config: ", err)
}

conn, err := sql.Open(config.DBDriver, config.DBSource)
Expand Down
33 changes: 29 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
version: "3"
services:
postgres:
container_name: before-after-db
image: mdillon/postgis:11
restart: always
environment:
- POSTGRES_USER=baato
- POSTGRES_PASSWORD=baato
- POSTGRES_DB=before-after
volumes:
- data/postgres:/var/lib/postgresql/data

backend:
image: before-after_backend:latest
build:
context: "."
dockerfile: "./Dockerfile.backend"
container_name: backend
entrypoint: ["/start.sh"]
restart: always
container_name: app-docker
ports:
- 8848:8848
environment:
- HOST_IP=${HOST_IP}
volumes:
- appdata:/appdata
- downloads:/downloads

migration:
image: before-after_backend:latest
container_name: migration
restart: on-failure
command: migrate -path ./backend/server/db/migration -database postgresql://baato:baato@postgres:5432/before-after?sslmode=disable -verbose up
depends_on:
- postgres
links:
- postgres

nginx:
restart: always
container_name: app-nginx
Expand All @@ -22,6 +45,8 @@ services:
- backend
volumes:
- appdata:/appdata

volumes:
appdata:
downloads:
data/postgres:

0 comments on commit f05c605

Please sign in to comment.