diff --git a/Dockerfile.backend b/Dockerfile.backend index 47be088..33177c9 100644 --- a/Dockerfile.backend +++ b/Dockerfile.backend @@ -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 / @@ -47,8 +50,6 @@ WORKDIR /server/backend/server RUN go build -WORKDIR /server - COPY before-after.env . -ENTRYPOINT ["/start.sh"] +WORKDIR /server diff --git a/backend/server/go.mod b/backend/server/go.mod index 6e707d6..c943ac1 100644 --- a/backend/server/go.mod +++ b/backend/server/go.mod @@ -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 diff --git a/backend/server/go.sum b/backend/server/go.sum index 2eb065a..7d82a63 100644 --- a/backend/server/go.sum +++ b/backend/server/go.sum @@ -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= diff --git a/backend/server/main.go b/backend/server/main.go index 88fd612..faeb7ba 100644 --- a/backend/server/main.go +++ b/backend/server/main.go @@ -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) diff --git a/docker-compose.yml b/docker-compose.yml index a97d81c..5b967ca 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 @@ -22,6 +45,8 @@ services: - backend volumes: - appdata:/appdata + volumes: appdata: downloads: + data/postgres: