Skip to content

Commit 66facb3

Browse files
authored
Merge pull request #154 from howToCodeWell/152-website-docker
Closes #150 Closes #151 Closes #152 Closes #153
2 parents 324ee0a + 0a2a0c8 commit 66facb3

18 files changed

+334
-74
lines changed

.github/workflows/api.yaml

-7
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,27 @@ jobs:
2828
- uses: actions/checkout@v2
2929

3030
- name: Start the containers
31-
working-directory: ./api
3231
run: docker-compose -f docker-compose.yml -f docker-compose.test.yml up -d --build
3332

3433
- name: Install composer packages
35-
working-directory: ./api
3634
run: docker-compose -f docker-compose.yml -f docker-compose.test.yml exec -T api composer install
3735

3836
- name: Run Database migrations
39-
working-directory: ./api
4037
run: docker-compose -f docker-compose.yml -f docker-compose.test.yml exec -T api bin/console --no-interaction doctrine:migration:migrate
4138

4239
- name: PHP Code Sniffer
43-
working-directory: ./api
4440
run: docker-compose -f docker-compose.yml -f docker-compose.test.yml exec -T api ./vendor/bin/phpcs src
4541

4642
- name: PHPStan
47-
working-directory: ./api
4843
run: docker-compose -f docker-compose.yml -f docker-compose.test.yml exec -T api ./vendor/phpstan/phpstan/phpstan analyse
4944

5045
- name: PHPUnit Unit tests
51-
working-directory: ./api
5246
run: docker-compose -f docker-compose.yml -f docker-compose.test.yml exec -T api ./vendor/bin/phpunit --testsuite unit --coverage-html tests/coverage/unit
5347

5448
- name: Test endpoint
5549
run: curl -X GET "http://localhost/api/v1"
5650

5751
- name: Stop containers
58-
working-directory: ./api
5952
if: always()
6053
run: docker-compose -f docker-compose.yml -f docker-compose.test.yml down
6154

.github/workflows/openapi.yaml

+1-6
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,16 @@ jobs:
2727
steps:
2828
- uses: actions/checkout@v2
2929

30-
- name: Start the containers
31-
working-directory: ./api
30+
- name: Start the containers]
3231
run: docker-compose -f docker-compose.yml -f docker-compose.test.yml up -d --build
3332

3433
- name: Install composer packages
35-
working-directory: ./api
3634
run: docker-compose -f docker-compose.yml -f docker-compose.test.yml exec -T api composer install
3735

3836
- name: Run Database migrations
39-
working-directory: ./api
4037
run: docker-compose -f docker-compose.yml -f docker-compose.test.yml exec -T api bin/console --no-interaction doctrine:migration:migrate
4138

4239
- name: Generate openapi.yaml
43-
working-directory: ./api
4440
run: docker-compose exec -T api bash -c "bin/console api:openapi:export --yaml" > ../docs/generated/openapi.yaml
4541

4642
- name: Archive openapi artifacts
@@ -51,7 +47,6 @@ jobs:
5147
docs/generated
5248
5349
- name: Stop containers
54-
working-directory: ./api
5550
if: always()
5651
run: docker-compose -f docker-compose.yml -f docker-compose.test.yml down
5752

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea
22
.vscode
3-
.DS_Store
3+
.DS_Store
4+
docker-compose.override.yml

README.md

+121-6
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,130 @@ Pull requests may be reviewed live on Twitch/YouTube.
2525

2626
See the [CONTRIBUTING](CONTRIBUTING.md) guide on how to contribute to the project.
2727

28+
---
2829

29-
## API
30+
## System Requirements
31+
32+
- Docker
33+
- Docker Compose
34+
- Node
35+
- NPM
36+
- Yarn
3037

31-
To install the API please read the [wiki page](https://github.com/howToCodeWell/code-quiz/wiki/API)
38+
---
39+
40+
## Local Install
3241

33-
## Database
34-
Please read the [wiki page](https://github.com/howToCodeWell/code-quiz/wiki/Database) on how to access and use the database.
42+
1. Clone the repository
43+
```bash
44+
git clone [email protected]:howToCodeWell/code-quiz.git
45+
```
3546

36-
# API Client
47+
2. Spin up the containers
3748

38-
To install the API client please read the [API-Client wiki page](https://github.com/howToCodeWell/code-quiz/wiki/API-Client)
49+
```bash
50+
docker-compose up -d
51+
```
3952

53+
3. Install database migrations
54+
```bash
55+
docker-compose exec api bin/console doctrine:migration:migrate
56+
```
57+
58+
4. Load data fixtures
59+
```bash
60+
docker-compose exec api bin/console doctrine:fixtures:load
61+
```
62+
63+
5. Add the following entry to the `/etc/hosts`
64+
65+
```bash
66+
127.0.0.1 codequiz.local
67+
127.0.0.1 api.codequiz.local
68+
```
69+
70+
## Generating the OpenAPI specification
71+
From the `api` folder run the following to create `openapi.yaml` in the `./docs/generated` folder. This is ignored from the code base
72+
```bash
73+
docker-compose exec api bash -c "bin/console api:openapi:export --yaml" > ./docs/generated/openapi.yaml
74+
```
75+
76+
## Install database and data
77+
1. Run the migrations
78+
```bash
79+
docker-compose exec api bash -c 'bin/console doctrine:migrations:migrate'
80+
```
81+
82+
2. Run the data fixtures
83+
```bash
84+
docker-compose exec api bash -c 'bin/console doctrine:fixtures:load'
85+
```
86+
---
87+
88+
## Accessing the projects
89+
90+
- The API can be reached at [http://api.codequiz.local/api/v1](http://api.codequiz.local/api/v1)
91+
- The website can be reached at [http://codequiz.local/](http://codequiz.local/)
92+
93+
---
94+
95+
## API request examples
96+
97+
**Get a list of quizzes**
98+
```bash
99+
curl -X 'GET' \
100+
'http://api.codequiz.local/api/v1/quizzes' \
101+
-H 'accept: application/ld+json'
102+
```
103+
**Get the first quiz**
104+
```bash
105+
curl -X 'GET' \
106+
'http://api.codequiz.local/api/v1/quiz/1' \
107+
-H 'accept: application/ld+json'
108+
```
109+
**Get the first question**
110+
```bash
111+
curl -X 'GET' \
112+
'http://api.codequiz.local/api/v1/question/1' \
113+
-H 'accept: application/ld+json'
114+
```
115+
116+
---
117+
118+
119+
# Running the API Client locally
120+
121+
## Install
122+
123+
1. Install the packages
124+
```
125+
yarn install
126+
```
127+
128+
2. Run the mock server
129+
```
130+
yarn start
131+
```
132+
133+
3. Generate the OpenAPI TypeScript module
134+
Make sure you have already generated the openapi spec file.
135+
136+
[See this guide for details](https://github.com/howToCodeWell/code-quiz/wiki/API#generating-the-openapi-specification)
137+
```
138+
yarn run generate-api
139+
```
140+
141+
## Testing
142+
143+
```
144+
yarn run lint
145+
```
146+
147+
```
148+
yarn run test
149+
```
150+
151+
---
152+
# Mobile App
153+
154+
Yet to be built

api/.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ phpstan.neon
2020
.phpunit.result.cache
2121
/tests/coverage
2222
###< phpunit/phpunit ###
23-
docker-compose.override.yml
23+
2424
###> symfony/phpunit-bridge ###
2525
.phpunit.result.cache
2626
/phpunit.xml

api/docker-compose.yml

-53
This file was deleted.
File renamed without changes.

docker-compose.yml

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
version: '3.5'
2+
3+
networks:
4+
code_quiz:
5+
name: code_quiz
6+
7+
volumes:
8+
db-data:
9+
10+
services:
11+
12+
proxy:
13+
build:
14+
dockerfile: Dockerfile
15+
context: ./proxy/
16+
networks:
17+
- code_quiz
18+
ports:
19+
- "80:80"
20+
restart: always
21+
volumes:
22+
- ./proxy/config/sites-enabled:/etc/nginx/sites-enabled
23+
- ./proxy/config/sites-enabled:/etc/nginx/sites-available
24+
- ./proxy/config/includes:/etc/nginx/includes
25+
- ./proxy/config/nginx.conf:/etc/nginx.conf
26+
27+
website:
28+
build:
29+
dockerfile: Dockerfile
30+
context: ./website/
31+
networks:
32+
- code_quiz
33+
34+
api:
35+
build:
36+
dockerfile: Dockerfile
37+
context: ./api/
38+
args:
39+
BUILD_ENV: dev
40+
depends_on:
41+
- db
42+
environment:
43+
- XDEBUG_MODE=off
44+
networks:
45+
- code_quiz
46+
volumes:
47+
- ./api/:/var/www/html
48+
- ./api/infra/api/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
49+
- ./api/infra/api/error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini
50+
51+
api-nginx:
52+
build:
53+
dockerfile: infra/nginx/Dockerfile
54+
context: ./api/
55+
args:
56+
BUILD_ENV: dev
57+
depends_on:
58+
- api
59+
networks:
60+
- code_quiz
61+
volumes:
62+
- ./api/:/var/www/html
63+
64+
db:
65+
image: mariadb:10.9.2
66+
restart: always
67+
environment:
68+
MARIADB_ROOT_PASSWORD: test
69+
MARIADB_DATABASE: code_quiz
70+
networks:
71+
- code_quiz
72+
volumes:
73+
- db-data:/var/lib/mysql

proxy/Dockerfile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM nginx
2+
3+
COPY ./config/sites-enabled /etc/nginx/sites-enabled
4+
COPY ./config/sites-enabled /etc/nginx/sites-available
5+
COPY ./config/includes /etc/nginx/includes
6+
COPY ./config/nginx.conf /etc/nginx/nginx.conf

proxy/config/includes/proxy.conf

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
proxy_set_header Host $host;
2+
proxy_set_header X-Real-IP $remote_addr;
3+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
4+
proxy_set_header X-Forwarded-Proto $scheme;
5+
proxy_buffering off;
6+
proxy_request_buffering off;
7+
proxy_http_version 1.1;
8+
proxy_intercept_errors on;

0 commit comments

Comments
 (0)