Skip to content

Commit

Permalink
Add README and one compose
Browse files Browse the repository at this point in the history
  • Loading branch information
boozec committed Mar 25, 2024
1 parent c01be10 commit bdb1d78
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 0 deletions.
76 changes: 76 additions & 0 deletions README.md
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
```
13 changes: 13 additions & 0 deletions api/README.md
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`
21 changes: 21 additions & 0 deletions build.sh
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
7 changes: 7 additions & 0 deletions api/docker-compose.yml → docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
volumes:
- postgres-data:/var/lib/postgresql/data
- ./api/schema:/docker-entrypoint-initdb.d
networks:
- default

Expand All @@ -24,5 +25,11 @@ services:
- "8080:8080"
restart: unless-stopped

bankservice-ui:
image: acmesky-bankservice-ui
container_name: bankservice-ui
ports:
- "8081:80"

volumes:
postgres-data:
19 changes: 19 additions & 0 deletions ui/Dockerfile
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;"]
9 changes: 9 additions & 0 deletions ui/README.md
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`

0 comments on commit bdb1d78

Please sign in to comment.