From b5a134e2109cc456bb101c6b03b4f93abf54610a Mon Sep 17 00:00:00 2001 From: Krish Chowdhary Date: Tue, 29 Dec 2020 04:51:59 -0500 Subject: [PATCH] minor reorganization, docker-compose for SQL --- Makefile | 10 +++++----- backend/Dockerfile | 13 +++++++++++-- backend/storage/README.md | 7 ------- docker-compose.yml | 14 ++++++++++++++ storage/Dockerfile.db | 5 +++++ storage/README.md | 13 +++++++++++++ storage/sql/build.sh | 9 +++++++++ .../sql/scripts}/discussion-board.sql | 0 8 files changed, 57 insertions(+), 14 deletions(-) delete mode 100644 backend/storage/README.md create mode 100644 storage/Dockerfile.db create mode 100644 storage/README.md create mode 100755 storage/sql/build.sh rename {backend/storage => storage/sql/scripts}/discussion-board.sql (100%) diff --git a/Makefile b/Makefile index 2c30b70..0227c11 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,20 @@ -build : +build: ifeq ($(env), local) cd frontend && npm install else docker-compose up --build endif -run : +run: ifeq ($(env), local) cd frontend && npm run dev else docker-compose up endif -down : +down: docker-compose down --remove-orphans -prettier : +prettier: cd frontend && npx prettier --write . - cd frontend && npm run lint -- --fix \ No newline at end of file + cd frontend && npm run lint -- --fix diff --git a/backend/Dockerfile b/backend/Dockerfile index 0d3e4fe..f31bb7a 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -2,16 +2,25 @@ FROM golang:buster RUN apt-get update RUN apt-get install curl -WORKDIR /app -COPY . . +ENV PGUSER=postgres; +ENV PGHOST=postgres; +ENV PGPASSWORD=password; +ENV PGDATABASE=postgres; + +WORKDIR /app RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.33.0 RUN curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh | sh -s -- -b $(go env GOPATH)/bin +COPY go.mod . +COPY go.sum . + RUN go mod download RUN go mod vendor +COPY . . + ENV PORT=3001 CMD [ "air" ] \ No newline at end of file diff --git a/backend/storage/README.md b/backend/storage/README.md deleted file mode 100644 index 7c0cfb7..0000000 --- a/backend/storage/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Pizza Storage - -All storage related files should go here, this includes but is not limited to: -- Schema -- Database configuration files/scripts -- Object storage -- Caching \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 353c66d..cf37263 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,15 @@ version: "3.8" services: + postgres: + build: + context: ./storage + dockerfile: Dockerfile.db + ports: + - 5432:5432 + environment: + POSTGRES_PASSWORD: password + POSTGRES_USER: postgres + POSTGRES_DB: postgres frontend: stdin_open: true build: @@ -24,4 +34,8 @@ services: - PORT=3001 volumes: - ./backend:/app + links: + - postgres + depends_on: + - postgres \ No newline at end of file diff --git a/storage/Dockerfile.db b/storage/Dockerfile.db new file mode 100644 index 0000000..ae39155 --- /dev/null +++ b/storage/Dockerfile.db @@ -0,0 +1,5 @@ +FROM postgres:13.1 +RUN apt-get update && apt-get install -y dos2unix +COPY sql/ /docker-entrypoint-initdb.d +RUN chmod +x /docker-entrypoint-initdb.d/build.sh +RUN find ./docker-entrypoint-initdb.d -type f -print0 | xargs -0 -n 1 -P 4 dos2unix diff --git a/storage/README.md b/storage/README.md new file mode 100644 index 0000000..08ec53c --- /dev/null +++ b/storage/README.md @@ -0,0 +1,13 @@ +# Dialog Storage + +## SQL + +The SQL scripts can be found under [sql](sql/). The custom Dockerfile builds the image, this should only be used for development purposes. + +## Notes + +All storage related files should go here, this includes but is not limited to: +- Schema +- Database configuration files/scripts +- Object storage +- Caching \ No newline at end of file diff --git a/storage/sql/build.sh b/storage/sql/build.sh new file mode 100755 index 0000000..0fe2fff --- /dev/null +++ b/storage/sql/build.sh @@ -0,0 +1,9 @@ +cd $(dirname $0) + +PGUSER=postgres +PGHOST=localhost +PGPASSWORD=postgres +PGDATABASE=postgres +PGPORT=5432 + +initilize=$(psql -f scripts/discussion-board.sql) diff --git a/backend/storage/discussion-board.sql b/storage/sql/scripts/discussion-board.sql similarity index 100% rename from backend/storage/discussion-board.sql rename to storage/sql/scripts/discussion-board.sql