fix: reload env variables before loading config

fix: read env
This commit is contained in:
Nicolas Meienberger 2023-11-16 13:29:00 +01:00 committed by Nicolas Meienberger
parent e0d52e79c1
commit 8bfafac7bd
5 changed files with 39 additions and 2015 deletions

View file

@ -51,7 +51,7 @@ jobs:
with:
context: .
file: ./packages/worker/Dockerfile
platforms: linux/amd64,linux/arm64
platforms: linux/amd64
push: true
tags: ghcr.io/${{ github.repository_owner }}/worker:${{ needs.create-tag.outputs.tagname }}
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/worker:buildcache
@ -82,7 +82,7 @@ jobs:
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
platforms: linux/amd64
push: true
tags: ghcr.io/${{ github.repository_owner }}/runtipi:${{ needs.create-tag.outputs.tagname }}
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/runtipi:buildcache
@ -169,13 +169,3 @@ jobs:
asset_path: cli/bin/cli-x64
asset_name: runtipi-cli-linux-x64
asset_content_type: application/octet-stream
- name: Upload ARM64 Linux CLI binary to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: cli/bin/cli-arm64
asset_name: runtipi-cli-linux-arm64
asset_content_type: application/octet-stream

View file

@ -5,6 +5,8 @@ services:
container_name: tipi-reverse-proxy
image: traefik:v2.8
restart: on-failure
depends_on:
- tipi-dashboard
ports:
- ${NGINX_PORT:-80}:80
- ${NGINX_PORT_SSL:-443}:443
@ -105,7 +107,7 @@ services:
tipi-worker:
condition: service_healthy
volumes:
- ./.env:/runtipi/.env
- ./.env:/runtipi/.env:ro
- ./state:/runtipi/state
- ./repos:/runtipi/repos:ro
- ./apps:/runtipi/apps

View file

@ -7,17 +7,18 @@ import { TerminalSpinner } from '@/utils/logger/terminal-spinner';
export class AppExecutors {
private readonly logger;
private queue: Queue;
private queueEvents: QueueEvents;
constructor() {
const { redisPassword } = getEnv();
this.logger = logger;
this.queue = new Queue('events', { connection: { host: '127.0.0.1', port: 6379, password: redisPassword } });
this.queueEvents = new QueueEvents('events', { connection: { host: '127.0.0.1', port: 6379, password: redisPassword } });
}
private getQueue = () => {
const { redisPassword } = getEnv();
const queue = new Queue('events', { connection: { host: '127.0.0.1', port: 6379, password: redisPassword } });
const queueEvents = new QueueEvents('events', { connection: { host: '127.0.0.1', port: 6379, password: redisPassword } });
return { queue, queueEvents };
};
private generateJobId = (event: Record<string, unknown>) => {
const { appId, action } = event;
return `${appId}-${action}`;
@ -33,9 +34,13 @@ export class AppExecutors {
const jobid = this.generateJobId({ appId, action: 'stop' });
const { queue, queueEvents } = this.getQueue();
const event = { type: 'app', command: 'stop', appid: appId, form: {}, skipEnv: true } satisfies SystemEvent;
const job = await this.queue.add(jobid, eventSchema.parse(event));
const result = await job.waitUntilFinished(this.queueEvents, 1000 * 60 * 5);
const job = await queue.add(jobid, eventSchema.parse(event));
const result = await job.waitUntilFinished(queueEvents, 1000 * 60 * 5);
await queueEvents.close();
await queue.close();
if (!result?.success) {
this.logger.error(result?.message);
@ -51,9 +56,13 @@ export class AppExecutors {
const jobid = this.generateJobId({ appId, action: 'start' });
const { queue, queueEvents } = this.getQueue();
const event = { type: 'app', command: 'start', appid: appId, form: {}, skipEnv: true } satisfies SystemEvent;
const job = await this.queue.add(jobid, eventSchema.parse(event));
const result = await job.waitUntilFinished(this.queueEvents, 1000 * 60 * 5);
const job = await queue.add(jobid, eventSchema.parse(event));
const result = await job.waitUntilFinished(queueEvents, 1000 * 60 * 5);
await queueEvents.close();
await queue.close();
if (!result.success) {
spinner.fail(`Failed to start app ${appId} see logs for more details (logs/error.log)`);

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,5 @@
import { z } from 'zod';
import { envSchema, settingsSchema } from '@runtipi/shared';
import { envSchema, envStringToMap, settingsSchema } from '@runtipi/shared';
import fs from 'fs-extra';
import nextConfig from 'next/config';
import { readJsonFile } from '../../common/fs.helpers';
@ -19,7 +19,16 @@ export class TipiConfig {
private config: z.infer<typeof envSchema> = {} as z.infer<typeof envSchema>;
constructor() {
const conf = { ...process.env, ...nextConfig()?.serverRuntimeConfig };
let envFile = '';
try {
envFile = fs.readFileSync('/runtipi/.env').toString();
} catch (e) {
Logger.error('❌ .env file not found');
}
const envMap = envStringToMap(envFile.toString());
const conf = { ...process.env, ...Object.fromEntries(envMap), ...nextConfig().serverRuntimeConfig };
const envConfig: z.infer<typeof envSchema> = {
postgresHost: conf.POSTGRES_HOST,
postgresDatabase: conf.POSTGRES_DBNAME,