feat: lamassu initial dockerize approach

feat: improve dockerization

feat: finished initial versions of dockerfiles

fix: small fixes to image building
This commit is contained in:
Sérgio Salgado 2022-03-17 16:04:34 +00:00
parent b0860cdea5
commit bd82285ecf
14 changed files with 484 additions and 20 deletions

View file

@ -1,6 +1,4 @@
#!/usr/bin/env node
const FileStore = require('migrate/lib/file-store')
const _ = require('lodash/fp')
const path = require('path')
require('dotenv').config({ path: path.resolve(__dirname, '../.env') })
@ -9,8 +7,6 @@ const db = require('../lib/db')
const migrate = require('../lib/migrate')
const { asyncLocalStorage, defaultStore } = require('../lib/async-storage')
const MIGRATE_STATE_PATH = process.env.MIGRATE_STATE_PATH
const createMigration = `CREATE TABLE IF NOT EXISTS migrations (
id serial PRIMARY KEY,
data json NOT NULL
@ -18,14 +14,7 @@ const createMigration = `CREATE TABLE IF NOT EXISTS migrations (
const select = 'select * from migrations limit 1'
const getMigrateFile = () => {
return new Promise((resolve, reject) => {
new FileStore(MIGRATE_STATE_PATH).load((err, store) => {
if (err) return reject(err)
return resolve(store)
})
})
}
const getMigrateFile = () => Promise.resolve()
const store = defaultStore()
asyncLocalStorage.run(store, () => {

View file

@ -8,7 +8,7 @@ const authErrors = require('../lib/new-admin/graphql/errors/authentication')
const name = process.argv[2]
const role = process.argv[3]
const domain = process.env.HOSTNAME
const domain = process.env.LAMASSU_ADMIN_SERVER_IP || process.env.HOSTNAME
if (!domain) {
console.error('No hostname configured in the environment')
@ -35,7 +35,7 @@ if (role !== 'user' && role !== 'superuser') {
asyncLocalStorage.run(defaultStore(), () => {
userManagement.createRegisterToken(name, role).then(token => {
if (domain === 'localhost') {
if (domain === 'localhost' && process.env.NODE_ENV !== 'production') {
console.log(`https://${domain}:3001/register?t=${token.token}`)
} else {
console.log(`https://${domain}/register?t=${token.token}`)

View file

@ -0,0 +1,27 @@
#!/usr/bin/env bash
FILE_1=/etc/ssl/certs/Lamassu_CA.pem
FILE_2=/etc/ssl/certs/Lamassu_OP.pem
FILE_3=/etc/ssl/certs/Lamassu_OP_Root_CA.pem
FILE_4=/etc/ssl/certs/Lamassu_OP_Root_CA.srl
FILE_5=/etc/ssl/private/Lamassu_OP.key
FILE_6=/etc/ssl/private/Lamassu_OP_Root_CA.key
echo "Executing migrations..."
node /app/packages/lamassu-server/bin/lamassu-migrate
echo "Checking for the existence of certificates..."
if [[ ! -f "$FILE_1" || ! -f "$FILE_2" || ! -f "$FILE_3" || ! -f "$FILE_4" || ! -f "$FILE_5" || ! -f "$FILE_6" ]]; then
echo "No Lamassu certificates found. Building them..."
bash /app/packages/lamassu-server/tools/build-docker-certs.sh
fi
USER_COUNT=$(node /app/packages/lamassu-server/tools/check-user-count.js)
if [[ $USER_COUNT == '0' ]]; then
echo "No initial user found. Creating master@lamassu.is..."
node /app/packages/lamassu-server/bin/lamassu-register master@lamassu.is superuser
fi
echo "Starting server..."
node /app/packages/lamassu-server/bin/lamassu-server