File tree 6 files changed +64
-46
lines changed
6 files changed +64
-46
lines changed Original file line number Diff line number Diff line change 1
1
### APP ########################################################################
2
- DATABASE_URL=" postgres://Dandoh:dandoh@127.0.0.1:5432/webhaskell?sslmode=disable"
3
- JWT_SECRET=" my_jwt_secret"
2
+ DATABASE_URL=postgres://Dandoh:dandoh@127.0.0.1:5432/webhaskell?sslmode=disable
3
+ JWT_SECRET=my_jwt_secret
4
4
5
5
### Docker ENV - PostgreSQL ####################################################
6
- POSTGRES_PASSWORD=" dandoh"
7
- POSTGRES_USER=" Dandoh"
8
- POSTGRES_DB=" webhaskell"
6
+ POSTGRES_PASSWORD=dandoh
7
+ POSTGRES_USER=Dandoh
8
+ POSTGRES_DB=webhaskell
Original file line number Diff line number Diff line change 1
- FROM haskell:8.6.5
1
+ FROM haskell:8.8.3
2
2
3
- # ## Install PostgreSQL
4
- RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list
5
- RUN curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
6
- RUN apt-get update
7
- RUN apt-get -y install postgresql-11
8
- RUN apt-get install libpq-dev
3
+ # ## Install libpq-dev for postgres haskell lib to be built & entr for detecting changes and restarting stack
4
+ RUN apt-get update \
5
+ && apt-get -y install libpq-dev entr \
6
+ && rm -rf /var/lib/apt/lists/*
9
7
10
- ARG pg_password
11
- ARG pg_user
12
- ARG pg_db
13
- USER postgres
14
- RUN /etc/init.d/postgresql start && psql --command "CREATE USER $pg_user WITH SUPERUSER PASSWORD '$pg_password';" && createdb -O $pg_user $pg_db
15
- USER root
8
+ WORKDIR /root/
16
9
17
- # ## Install dbmate
18
- RUN curl -fsSL -o /usr/local/bin/dbmate https://github.com/amacneil/dbmate/releases/download/v1.7.0/dbmate-linux-amd64
19
- RUN chmod +x /usr/local/bin/dbmate
10
+ # # Prebuild dependencies
11
+ COPY stack.* package.yaml /root/
12
+ RUN stack build --only-dependencies
20
13
21
- WORKDIR /root/
22
14
23
15
COPY ./entrypoint.sh /opt/entrypoint.sh
24
16
RUN chmod +x /opt/entrypoint.sh
25
- ENTRYPOINT ["/opt/entrypoint.sh" ]
26
17
18
+ COPY . /root
19
+
20
+ ENTRYPOINT ["/opt/entrypoint.sh" ]
Original file line number Diff line number Diff line change @@ -71,24 +71,19 @@ You can also access Graphql Playground at [http://localhost:8080/graphiql](http:
71
71
$ cp .env.default .env
72
72
```
73
73
- (Optional) Edit anything you need in the .env file
74
+
74
75
- Create and start docker containers
75
76
``` terminal
76
- $ docker-compose up -d
77
- ```
78
- - Enter inside the docker workspace container
79
- ``` terminal
80
- $ docker exec -it web-haskell-graphql-postgres-boilerplate_workspace_1 /bin/bash
81
- ```
82
- - Migrations
83
- ``` terminal
84
- $ dbmate up
85
- ```
86
- - Run webserver
87
- ``` terminal
88
- $ stack run
77
+ $ docker-compose up
89
78
```
79
+
90
80
- Now you can visit: http://localhost:8080/ in your local machine.
91
81
82
+ - Migrations will automatically run, and you can run them manually anytime using
83
+ ``` terminal
84
+ $ docker-compose up dbmate
85
+ ```
86
+ - Stack will restart whenever you change any .hs file, thanks to [ entr] ( http://eradman.com/entrproject/ )
92
87
93
88
94
89
## Contributors
@@ -97,3 +92,4 @@ PR are more than welcome. The only note is we use `ormolu` to format codes.
97
92
98
93
- [ Nhan Thai] ( https://github.com/dandoh )
99
94
- [ Pacific01] ( https://github.com/Pacific01 )
95
+ - [ Emad Shaaban] ( https://github.com/emadshaaban92 )
Original file line number Diff line number Diff line change @@ -2,15 +2,43 @@ version: '3.7'
2
2
3
3
services :
4
4
5
+ db :
6
+ image : postgres:12.2
7
+ environment :
8
+ - POSTGRES_PASSWORD
9
+ - POSTGRES_USER
10
+ - POSTGRES_DB
11
+ volumes :
12
+ - db-data:/var/lib/postgresql/data
13
+
5
14
workspace :
6
- build :
7
- context : ./
8
- dockerfile : Dockerfile
9
- args :
10
- pg_password : ${POSTGRES_PASSWORD}
11
- pg_user : ${POSTGRES_USER}
12
- pg_db : ${POSTGRES_DB}
15
+ build : ./
16
+ depends_on :
17
+ - db
18
+ environment :
19
+ - DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}?sslmode=disable
20
+ - JWT_SECRET
13
21
volumes :
14
- - ./:/root/
22
+ - ./app:/root/app
23
+ - ./images:/root/images
24
+ - ./src:/root/src
25
+ - ./.env:/root/.env
26
+ - ./graphiql.html:/root/graphiql.html
27
+ - ./schema.graphql:/root/schema.graphql
28
+ - ./package.yaml:/root/package.yaml
29
+ - ./stack.yaml:/root/stack.yaml
15
30
ports :
16
31
- 8080:8080
32
+
33
+ dbmate :
34
+ image : amacneil/dbmate:v1.8.0
35
+ environment :
36
+ - DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}?sslmode=disable
37
+ depends_on :
38
+ - db
39
+ volumes :
40
+ - ./db:/db/
41
+ command : --wait up
42
+
43
+ volumes :
44
+ db-data:
Original file line number Diff line number Diff line change @@ -22,6 +22,6 @@ trap 'kill ${!}; term_handler' SIGTERM
22
22
# wait forever
23
23
while true
24
24
do
25
- tail -f /dev/null & wait ${ ! }
25
+ ls -d ** / * .hs | entr -d -r stack run
26
26
done
27
27
Original file line number Diff line number Diff line change 17
17
#
18
18
# resolver: ./custom-snapshot.yaml
19
19
# resolver: https://example.com/snapshots/2018-01-01.yaml
20
- resolver : lts-15.9
20
+ resolver : lts-15.12
21
21
22
22
# User packages to be built.
23
23
# Various formats can be used as shown in the example below.
You can’t perform that action at this time.
0 commit comments