-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# ACME Sky - Bank Service | ||
|
||
This repo refers to the Bank service used by ACME Sky. | ||
|
||
## `./api` folder | ||
|
||
It exposes a REST API with three endpoints: | ||
|
||
- `POST /payments/` used to create new payments. An example is: | ||
|
||
``` | ||
curl -X POST http://localhost:8080/payments/ -H 'content-type: application/json' -H 'accept: application/json, */*;q=0.5' -d '{"owner":"John Doe","amount":30.4,"description":"Flight to CTA"}' | ||
``` | ||
|
||
- `GET /payments/<id>/` used to get info about a payment. An example is: | ||
|
||
``` | ||
curl http://localhost:8080/payments/20e8f98d-f67e-4e40-9ddb-77b786e61560/ | ||
HTTP/1.1 200 OK | ||
Access-Control-Allow-Headers: Content-Type | ||
Access-Control-Allow-Methods: OPTIONS, GET, HEAD, POST | ||
Access-Control-Allow-Origin: * | ||
Access-Control-Max-Age: 86400 | ||
Allow: OPTIONS, GET, HEAD, POST | ||
Content-Length: 162 | ||
Content-Type: application/json | ||
{ | ||
"id": "20e8f98d-f67e-4e40-9ddb-77b786e61560", | ||
"owner": "John Doe", | ||
"amount": 30.4, | ||
"description": "Flight to BLQ", | ||
"paid": true, | ||
"created_at": "2024-03-25 15:34:45.093465" | ||
} | ||
``` | ||
|
||
- `POST /payments/<id>/pay/` used to change `paid` status. It is a fake: | ||
card information are ignored. Payload can be empty. | ||
|
||
> [!NOTE] | ||
> Do not forget to create a PostgreSQL database and link it to the API through | ||
> `DATABASE_URL` environment variable. | ||
## `./ui` folder | ||
|
||
A simple frontend built in Vue+Vite. You must define `VITE_BACKEND_URL` which | ||
points to the API. | ||
|
||
## Build | ||
|
||
> [!TIP] | ||
> You can use `./build.sh` for a step-by-step guide for deploying. | ||
|
||
You need to set up | ||
``` | ||
POSTGRES_USER=user | ||
POSTGRES_PASSWORD=pass | ||
POSTGRES_DB=db | ||
DATABASE_URL=postgres://user:pass@bankservice-postgres:5432/db | ||
``` | ||
|
||
and build | ||
|
||
``` | ||
docker build -t acmesky-bankservice-api api | ||
docker build -t acmesky-bankservice-ui --build-arg VITE_BACKEND_URL=http://localhost:8080 ui | ||
``` | ||
|
||
after that you can put everything up | ||
|
||
``` | ||
docker compose up | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# API | ||
|
||
Steps for development | ||
|
||
1. Install Linux deps `ocaml libev-dev libpq-dev pkg-config` | ||
|
||
2. Install project deps `opam install --deps-only .` | ||
|
||
3. Build `opam exec -- dune build` | ||
|
||
4. Set up `DATABASE_URL` variable. It should be a PostgreSQL uri. | ||
|
||
5. Run `dune run acmebank` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
read -p "POSTGRES_USER [acme]: " pg_user | ||
pg_user=${pg_user:-'acme'} | ||
|
||
read -p "POSTGRES_PASSWORD [pass]: " pg_pass | ||
pg_pass=${pg_pass:-'pass'} | ||
|
||
read -p "POSTGRES_DB [db]: " pg_db | ||
pg_db=${pg_db:-'db'} | ||
|
||
read -p "VITE_BACKEND_URL [http://localhost:8080]: " bank_api | ||
bank_api=${bank_api:-'http://localhost:8080'} | ||
|
||
export POSTGRES_USER="$pg_user" | ||
export POSTGRES_PASSWORD="$pg_pass" | ||
export POSTGRES_DB="$pg_db" | ||
export DATABASE_URL="postgres://$pg_user:$pg_pass@bankservice-postgres:5432/$pg_db" | ||
|
||
docker build -t acmesky-bankservice-api api | ||
docker build -t acmesky-bankservice-ui --build-arg VITE_BACKEND_URL="$bank_api" ui | ||
|
||
docker compose up |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# build stage | ||
FROM node:16-alpine as build-stage | ||
WORKDIR /app | ||
COPY package*.json ./ | ||
|
||
ARG VITE_APP_BACKEND_URL | ||
|
||
RUN npm install | ||
RUN npx browserslist@latest --update-db | ||
COPY . . | ||
RUN npm run build | ||
|
||
# production stage | ||
FROM nginx:stable-alpine as production-stage | ||
COPY ./nginx.conf /temp/prod.conf | ||
RUN envsubst /app < /temp/prod.conf > /etc/nginx/conf.d/default.conf | ||
COPY --from=build-stage /app/dist/ /usr/share/nginx/html | ||
EXPOSE 80 | ||
CMD ["nginx", "-g", "daemon off;"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# UI | ||
|
||
Steps for development | ||
|
||
1. Install deps `npm i` | ||
|
||
2. Set up `VITE_BACKEND_URL` | ||
|
||
3. Run `npm run dev` |