Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add knex migration #179

Merged
merged 8 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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