Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added integration with Docker Compose #88

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
0ffb92c
Added SQL script to create database
Andrew15-5 Aug 16, 2022
e5dcc68
Added Dockerfile for PostgreSQL image with 0 vulns
Andrew15-5 Aug 16, 2022
cfe9e07
Added build functionality to docker-compose.yml
Andrew15-5 Aug 16, 2022
0f1d660
Added Docker Compose file for production
Andrew15-5 Aug 16, 2022
d423f3b
Merge pull request #79 from Andrew15-5/78-add-source-files-for-db-cre…
Andrew15-5 Aug 16, 2022
98a0e57
Added dotenv module for auto .env import
Andrew15-5 Aug 18, 2022
82f45d9
Added SIGINT & SIGTERM handlers
Andrew15-5 Aug 18, 2022
4769749
Added Dockerfile for this app
Andrew15-5 Aug 18, 2022
7fd5fd4
Merge pull request #81 from Andrew15-5/80-put-app-in-docker-container
Andrew15-5 Aug 18, 2022
7fac5f9
Added package-lock.json; removed it from .gitignore
Andrew15-5 Aug 19, 2022
8bb72c5
Merge pull request #83 from Andrew15-5/82-add-package-lock.json
Andrew15-5 Aug 19, 2022
0286ec4
Added Andrew15-5/ref-app as a submodule
Andrew15-5 Aug 19, 2022
648e4ec
Added REF_APP_SERVER_HOST env var
Andrew15-5 Aug 19, 2022
388577b
Added Ref-App service in Docker Compose files
Andrew15-5 Aug 19, 2022
b61a8e7
Merge pull request #85 from Andrew15-5/84-put-ref-app-in-docker-conta…
Andrew15-5 Aug 19, 2022
f95fd74
Added .env.sample
Andrew15-5 Aug 19, 2022
15f6ff7
Updated ref-app submodule from 623e8de to db301d8
Andrew15-5 Aug 19, 2022
4935562
Merge pull request #87 from Andrew15-5/86-add-.env.sample
Andrew15-5 Aug 19, 2022
e0b8db4
Added showcase section in README.md
Andrew15-5 Jan 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# To connect to database from Grocery Store/ref-app server
PGUSER=postgres
PGHOST=db
PGPORT=5432
PGPASSWORD=pass
PGDATABASE=grocery_store

# Used by Grocery Store server
JWT_SECRET_KEY=8fd2f8c4bebfec7aafddfdd850f34ac0fc4942dc16a840691a289825a880e288ffcde797d7d35cb349c6289ef4482d4aed75a191c5046fa3bd1e27989c80c0a4
PEPPER=G6dNLnjAmkzQyeM7gZTJ

# Grocery Store server's port
SERVER_PORT=3000

# ref-app server's host:port
REF_APP_SERVER_HOST=ref-app
REF_APP_SERVER_PORT=4000

# Used by Docker Compose
IMAGE_HOST=ghcr.io/andrew15-5/
POSTGRES_PASSWORD=pass
21 changes: 21 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# To connect to database from Grocery Store/ref-app server
PGUSER=
PGHOST=
PGPORT=
PGPASSWORD=
PGDATABASE=

# Used by Grocery Store server
JWT_SECRET_KEY=
PEPPER=

# Grocery Store server's port
SERVER_PORT=

# ref-app server's host:port
REF_APP_SERVER_HOST=
REF_APP_SERVER_PORT=

# Used by Docker Compose
IMAGE_HOST=
POSTGRES_PASSWORD=
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.env
dist
node_modules
package-lock.json
*.sh
*.bat
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "ref-app"]
path = ref-app
url = [email protected]:Andrew15-5/ref-app.git
13 changes: 13 additions & 0 deletions .justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set dotenv-load

default:
git submodule update --init --recursive
cp .env ref-app/
docker compose up

clean:
rm -rf node_modules dist ref-app
docker compose down -v

docker-rmi:
docker rmi ${IMAGE_HOST}postgressql_for_grocery_store ${IMAGE_HOST}grocery_store ${IMAGE_HOST}ref-app
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM node:18.7-alpine3.16@sha256:02a5466bd5abde6cde29c16d83e2f5a10eec11c8dcefa667a2c9f88a7fa8b0b3 as transpiledTS
COPY package.json package-lock.json ./
RUN npm ci
COPY src/ tsconfig.json ./
RUN npx tsc

FROM node:18.7-alpine3.16@sha256:02a5466bd5abde6cde29c16d83e2f5a10eec11c8dcefa667a2c9f88a7fa8b0b3 as production
ENV NODE_ENV production
RUN apk add --no-cache jq
COPY package.json package-lock.json ./
RUN npm ci
RUN mv package.json pckg.jsn && jq '{main:.main}' pckg.jsn > package.json

FROM node:18.7-alpine3.16@sha256:02a5466bd5abde6cde29c16d83e2f5a10eec11c8dcefa667a2c9f88a7fa8b0b3
ENV NODE_ENV production
USER node
WORKDIR /usr/src/app/
ENTRYPOINT ["node", "."]
ARG SERVER_PORT
EXPOSE ${SERVER_PORT}
COPY --chown=node:node --from=production node_modules/ ./node_modules/
COPY --chown=node:node --from=production package.json .
COPY --chown=node:node .env .
COPY --chown=node:node views views
COPY --chown=node:node public public
COPY --chown=node:node --from=transpiledTS dist/ ./dist/
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@

## About

Repository was created as a part of university practise and as an example of a
"store" that can integrate the [ref-app](<https://github.com/Andrew15-5/ref-app>).
Referral link system + Internet shop. When a user is buying products through a
referral link the referral link owner will get a percent of the total price
paid.

Repository was created as a part of university practicum and as an example of a
"shop" that can integrate the [ref-app](<https://github.com/Andrew15-5/ref-app>).

## Showcase

```sh
git clone https://github.com/Andrew15-5/Grocery-Store.git -b dev
just
```

## Contributors

Expand Down
4 changes: 4 additions & 0 deletions db/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM postgres:14.4-alpine3.16@sha256:4ea11d3110e47a360ace22bbca73b2ebaa6dd2eec289e0b6949e4d96e2d4ba4c
RUN apk add -u --no-cache zlib
USER postgres
ADD add_database.sql /docker-entrypoint-initdb.d
52 changes: 52 additions & 0 deletions db/add_database.sql

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions docker-compose-production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: "2.2"

services:
PostgreSQL_for_Grocery_Store:
image: ${IMAGE_HOST}postgressql_for_grocery_store
environment:
POSTGRES_PASSWORD:
restart: always
Grocery_Store:
image: ${IMAGE_HOST}grocery_store
depends_on:
- PostgreSQL_for_Grocery_Store
- Ref-App
ports:
- ${SERVER_PORT}:${SERVER_PORT}
links:
- PostgreSQL_for_Grocery_Store:${PGHOST}
- Ref-App:ref-app
restart: always
Ref-App:
image: ${IMAGE_HOST}ref-app
depends_on:
- PostgreSQL_for_Grocery_Store
links:
- PostgreSQL_for_Grocery_Store:${PGHOST}
restart: always
28 changes: 26 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,36 @@ version: "2.2"
services:
PostgreSQL_for_Grocery_Store:
image: ${IMAGE_HOST}postgressql_for_grocery_store
ports:
- ${PGPORT}:5432
build:
context: ./db/
environment:
POSTGRES_PASSWORD:
volumes:
- postgresql_for_grocery_store_data:/var/lib/postgresql/data
Grocery_Store:
image: ${IMAGE_HOST}grocery_store
depends_on:
- PostgreSQL_for_Grocery_Store
- Ref-App
build:
context: .
args:
SERVER_PORT:
ports:
- ${SERVER_PORT}:${SERVER_PORT}
links:
- PostgreSQL_for_Grocery_Store:${PGHOST}
- Ref-App:ref-app
Ref-App:
image: ${IMAGE_HOST}ref-app
depends_on:
- PostgreSQL_for_Grocery_Store
build:
context: ./ref-app/
args:
SERVER_PORT: ${REF_APP_SERVER_PORT}
links:
- PostgreSQL_for_Grocery_Store:${PGHOST}

volumes:
postgresql_for_grocery_store_data:
Loading