Skip to content

Commit

Permalink
chore: initial docker compose deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed Feb 16, 2024
1 parent 41cf08b commit 463b03a
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 46 deletions.
69 changes: 44 additions & 25 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
version: '3.9'
services:
mysql:
image: mysql
image: mysql:5.7
container_name: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
healthcheck:
Expand All @@ -10,18 +11,17 @@ services:
timeout: 5s
retries: 5
environment:
MYSQL_ROOT_HOST: "%"
MYSQL_ROOT_PASSWORD: start123
ports:
- '3306:3306'
redis:
image: bitnami/redis
healthcheck:
test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ]
interval: 3s
timeout: 5s
retries: 5
ports:
- '6379:6379'
environment:
ALLOW_EMPTY_PASSWORD: yes
mq:
image: bitnami/rabbitmq
healthcheck:
Expand All @@ -31,47 +31,66 @@ services:
retries: 5
ports:
- '5672:5672'
environment:
RABBITMQ_USERNAME: root
RABBITMQ_PASSWORD: start123
vault:
image: vault
ports:
- '8090:8090'
image: vault:1.12.0
healthcheck:
test: [ "CMD", "wget", "--spider", "--proxy", "off", "http://localhost:8090/v1/sys/health?standbyok=true" ]
interval: 10s
timeout: 3s
retries: 10
start_period: 5s
environment:
VAULT_DEV_ROOT_TOKEN_ID: start123
VAULT_DEV_LISTEN_ADDRESS: 0.0.0.0:8090
authup:
image: authup/authup
pull_policy: always
restart: always
depends_on:
- mysql
- redis
- vault
mysql:
condition: service_healthy
redis:
condition: service_healthy
vault:
condition: service_healthy
ports:
- '3000:3010'
- '3010:3000'
environment:
DB_TYPE: 'mysql'
DB_USER: 'root'
DB_PASSWORD: 'start'
DB_HOST: 'mysql'
DB_USERNAME: 'root'
DB_PASSWORD: 'start123'
DB_DATABASE: 'auth'
VAULT: start123@http://vault:8090/v1/
serverCore:
build: './Dockerfile'
REDIS: redis://redis
server-core:
build: '.'
restart: always
depends_on:
- authup
- mq
- mysql
- redis
- vault
authup:
condition: service_healthy
mq:
condition: service_healthy
mysql:
condition: service_healthy
redis:
condition: service_healthy
vault:
condition: service_healthy
ports:
- '3000:3001'
- '3001:3000'
environment:
REDIS_CONNECTION_STRING: redis://redis
VAULT_CONNECTION_STRING: start123@http://vault:8090/v1/
RABBITMQ_CONNECTION_STRING: amqp://root:start123@mq
# RABBITMQ_CONNECTION_STRING: amqp://root:start123@mq
PUBLIC_URL: http://localhost:3001/
AUTHUP_API_URL: http://authup:3000/
DB_TYPE: 'mysql'
DB_USER: 'root'
DB_PASSWORD: 'start'
DB_HOST: 'mysql'
DB_USERNAME: 'root'
DB_PASSWORD: 'start123'
DB_DATABASE: 'core'

8 changes: 4 additions & 4 deletions packages/server-core/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ import { createHttpServer } from '../http/server';
import { generateSwaggerDocumentation } from '../http/swagger';

export async function startCommand() {
const config = await createConfig();
const config = createConfig();

const logger = useLogger();

logger.info(`Environment: ${useEnv('env')}`);
logger.info(`WritableDirectoryPath: ${getWritableDirPath()}`);
logger.info(`Port: ${useEnv('port')}`);
logger.info(`Public-URL: ${useEnv('apiUrl')}`);
logger.info(`Authup-URL: ${useEnv('authupApiUrl')}`);
logger.info(`Docs-URL: ${new URL('docs/', useEnv('apiUrl')).href}`);
logger.info(`Public-URL: ${useEnv('publicURL')}`);
logger.info(`Authup-URL: ${useEnv('authupApiURL')}`);
logger.info(`Docs-URL: ${new URL('docs/', useEnv('publicURL')).href}`);

logger.info('Generating documentation...');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export async function saveRemoteRegistryProjectWebhook(
name: 'api',
targets: [
buildRegistryWebhookTarget({
url: useEnv('apiUrl'),
url: useEnv('publicURL'),
robot: {
id: engineData.id,
secret: engineData.secret,
Expand Down
13 changes: 7 additions & 6 deletions packages/server-core/src/config/env/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
readInt,
} from 'envix';
import { config } from 'dotenv';
import type { EnvironmentName } from './constants';
import { EnvironmentName } from './constants';
import type { Environment } from './type';

config({
Expand All @@ -34,9 +34,10 @@ export function useEnv(key?: string) : any {
return instance;
}

const port = readInt('PORT', 3000);
instance = {
env: read('NODE_ENV', 'development') as `${EnvironmentName}`,
port: readInt('PORT', 3002),
env: read('NODE_ENV', EnvironmentName.DEVELOPMENT) as `${EnvironmentName}`,
port,

jwtMaxAge: readInt('JWT_MAX_AGE', 3600),

Expand All @@ -56,9 +57,9 @@ export function useEnv(key?: string) : any {
read('VAULT_CONNECTION_STRING'),
]),

apiUrl: read('API_URL', 'http://127.0.0.1:3002/'),
authupApiUrl: read('AUTHUP_API_URL', 'http://127.0.0.1:3010/'),
appUrl: read('APP_URL', 'http://127.0.0.1:3000/'),
publicURL: read('PUBLIC_URL', `http://127.0.0.1:${port}/`),
authupApiURL: read('AUTHUP_API_URL', 'http://127.0.0.1:3010/'),
appURL: read('APP_URL', 'http://127.0.0.1:3000/'),

skipProjectApproval: readBool('SKIP_PROJECT_APPROVAL'),
skipAnalysisApproval: readBool('SKIP_ANALYSIS_APPROVAL'),
Expand Down
6 changes: 3 additions & 3 deletions packages/server-core/src/config/env/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export interface Environment {
rabbitMqConnectionString?: string | boolean,
vaultConnectionString: string | boolean,

apiUrl: string,
authupApiUrl: string,
appUrl: string,
publicURL: string,
authupApiURL: string,
appURL: string,

skipProjectApproval: boolean,
skipAnalysisApproval: boolean,
Expand Down
4 changes: 2 additions & 2 deletions packages/server-core/src/config/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function createConfig() : Config {
// ---------------------------------------------

const authupClient = new APIClient({
baseURL: useEnv('authupApiUrl'),
baseURL: useEnv('authupApiURL'),
});

let tokenCreator : TokenCreatorOptions;
Expand All @@ -60,7 +60,7 @@ export function createConfig() : Config {
}

mountClientResponseErrorTokenHook(authupClient, {
baseURL: useEnv('authupApiUrl'),
baseURL: useEnv('authupApiURL'),
tokenCreator,
});

Expand Down
2 changes: 1 addition & 1 deletion packages/server-core/src/http/middleware/authup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function registerAuthupMiddleware(router: Router) {
const middleware = createHTTPMiddleware({
tokenByCookie: (req, cookieName) => useRequestCookie(req, cookieName),
tokenVerifier: {
baseURL: useEnv('authupApiUrl'),
baseURL: useEnv('authupApiURL'),
creator: tokenCreator,
cache: tokenCache,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/server-core/src/http/middleware/swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ import { getWritableDirPath, useEnv } from '../../config';
export function registerSwaggerMiddleware(router: Router) {
const document = loadSync(path.join(getWritableDirPath(), 'swagger.json'));
router.use('/docs', swaggerUI(document, {
baseURL: useEnv('apiUrl'),
baseURL: useEnv('publicURL'),
}));
}
4 changes: 2 additions & 2 deletions packages/server-core/src/http/swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function generateSwaggerDocumentation() {
allow: ['**/@authup/**'],
},
yaml: true,
servers: [useEnv('apiUrl')],
servers: [useEnv('publicURL')],
name: 'API Documentation',
description: 'Explore the REST Endpoints of the Central API.',
version: packageJson.version,
Expand All @@ -42,7 +42,7 @@ export async function generateSwaggerDocumentation() {
type: 'oauth2',
flows: {
password: {
tokenUrl: new URL('token', useEnv('apiUrl')).href,
tokenUrl: new URL('token', useEnv('publicURL')).href,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/server-realtime/src/config/env/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function useEnv(key?: string) : any {

instance = {
env: read('NODE_ENV', 'development') as `${EnvironmentName}`,
port: readInt('PORT', 3001),
port: readInt('PORT', 3000),
redisConnectionString: read('REDIS_CONNECTION_STRING', null),
vaultConnectionString: read('VAULT_CONNECTION_STRING', 'start123@http://127.0.0.1:8090/v1/'),

Expand Down

0 comments on commit 463b03a

Please sign in to comment.