Skip to content

Commit

Permalink
Merge pull request #179 from celluloid-camp/create-knex-migration
Browse files Browse the repository at this point in the history
Add knex migration
  • Loading branch information
younes200 authored Nov 9, 2022
2 parents f6010de + 491be78 commit e7bbfd2
Show file tree
Hide file tree
Showing 33 changed files with 1,226 additions and 2,175 deletions.
29 changes: 29 additions & 0 deletions .env.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
NODE_ENV=test

# HTTP server port. Do not change unless you know what you're doing.
CELLULOID_LISTEN_PORT=3001
# Postgres server IP address or hostname.
CELLULOID_PG_HOST=postgres
# Postgres port.
CELLULOID_PG_PORT=5432
# Postgres database name.
CELLULOID_PG_DATABASE=postgres
# Postgres database user.
CELLULOID_PG_USER=postgres
# Postgres database password.
CELLULOID_PG_PASSWORD=postgres
# Postgres connection pool config. Change at your own risk.
CELLULOID_PG_MAX_POOL_SIZE=20
CELLULOID_PG_IDLE_TIMEOUT=30000
# Cookie secret key. Generate something random and long.
CELLULOID_COOKIE_SECRET=cisecret3

CELLULOID_REDIS_URL=redis://localhost

# email params. Check with your SMTP provider
CELLULOID_SMTP_HOST=
CELLULOID_SMTP_USER=
CELLULOID_SMTP_PASSWORD=
CELLULOID_SMTP_TLS=false
CELLULOID_SMTP_PORT=465

54 changes: 54 additions & 0 deletions .github/workflows/dockerfile-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Dockerfile CI

on: [pull_request]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]

services:
redis:
image: redis
ports:
- "0.0.0.0:6379:6379"
postgres:
image: postgres:14
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- "0.0.0.0:5432:5432"
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: setup database
run: |
cp .env.ci .env
yarn --frozen-lockfile
env:
CI: true
- name: "Run docker server build"
run:
docker build --tag celluloid-server .
- name: "ifconfig -a"
run: "ifconfig -a"
- name: "Start docker server"
run:
docker run --rm -d --init -p 3001:3001 --env-file .env -e NODE_ENV=production -e CELLULOID_PG_HOST=172.17.0.1 -e CELLULOID_REDIS_URL=redis://172.17.0.1
--name celluloid-server celluloid-server
- name: "Test docker"
run: node .github/workflows/test-docker.js
- name: "Tear down docker"
run: docker kill celluloid-server
52 changes: 52 additions & 0 deletions .github/workflows/test-docker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const fetch = require("node-fetch");
const AbortController = require("abort-controller");
const { execSync } = require("child_process");

const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

async function main() {
let attempts = 0;
let response;
while (true) {
try {
const controller = new AbortController();
const timeout = setTimeout(() => {
controller.abort();
}, 3000);
try {
response = await fetch("http://localhost:3001", {
signal: controller.signal,
});
} finally {
clearTimeout(timeout);
}
if (!response.ok) {
throw new Error("Try again");
}
break;
} catch (e) {
attempts++;
if (attempts <= 30) {
console.log(`Server is not ready yet: ${e.message}`);
execSync("docker logs celluloid-server", { stdio: "inherit" });
} else {
console.log(`Server never came up, aborting :(`);
process.exit(1);
}
await sleep(1000);
}
}
const text = await response.text();

// Check for known text on homepage
if (!text.includes("Institut Catholique de Paris")) {
throw new Error("Failed to confirm server works.");
}

console.log("Docker tests passed.");
}

main().catch((e) => {
console.error(e);
process.exit(1);
});
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,6 @@ In a terminal, at the root of the repository, run

Open the newly created .env file with your favorite text editor and set the values that'll work for you.

### Database provisioning

Make sure your PostgreSQL server is up. In a terminal, go to the `bin` directory and run the `create_schema` script:

cd bin
./create_schema.sh

If this fails, you most certainly got your PostgreSQL server configuration or your `.env` file wrong.


### Docker container

Expand Down Expand Up @@ -127,7 +118,7 @@ You should be able to access your app at http://localhost:3001

Open a terminal at the root of your repository, then run

docker run -f Dockerfile.webapp
docker compose -f Dockerfile

(make sure [Docker](https://www.docker.com/get-started) is properly installed beforehand!)

Expand Down
Loading

0 comments on commit e7bbfd2

Please sign in to comment.