fix: Expose ports for services

This commit is contained in:
Andras Bacsai 2022-05-09 15:18:25 +02:00
parent 24c655d7ef
commit 6ac8dd8907
10 changed files with 29 additions and 30 deletions

View File

@ -527,7 +527,8 @@
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="exposePort" class="text-base font-bold text-stone-100">Exposed Port</label> <label for="exposePort" class="text-base font-bold text-stone-100">Exposed Port</label>
<input <input
readonly={!$session.isAdmin} readonly={!$session.isAdmin && !isRunning}
disabled={!$session.isAdmin || isRunning}
name="exposePort" name="exposePort"
id="exposePort" id="exposePort"
bind:value={application.exposePort} bind:value={application.exposePort}

View File

@ -27,7 +27,6 @@
let loading = false; let loading = false;
let loadingVerification = false; let loadingVerification = false;
let dualCerts = service.dualCerts; let dualCerts = service.dualCerts;
let showExposePort = service.exposePort !== null;
async function handleSubmit() { async function handleSubmit() {
loading = true; loading = true;
@ -161,31 +160,20 @@
on:click={() => !isRunning && changeSettings('dualCerts')} on:click={() => !isRunning && changeSettings('dualCerts')}
/> />
</div> </div>
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center px-10">
<Setting <label for="exposePort" class="text-base font-bold text-stone-100">Exposed Port</label>
isCenter={false}
bind:setting={showExposePort}
on:click={() => {
showExposePort = !showExposePort;
service.exposePort = undefined;
}}
title={$t('application.expose_a_port')}
description="Expose a port to the host system"
/>
</div>
{#if showExposePort}
<div class="grid grid-cols-2 items-center">
<label for="exposePort" class="text-base font-bold text-stone-100">Expose Port</label>
<input <input
readonly={!$session.isAdmin} readonly={!$session.isAdmin && !isRunning}
disabled={!$session.isAdmin || isRunning}
name="exposePort" name="exposePort"
id="exposePort" id="exposePort"
bind:value={service.exposePort} bind:value={service.exposePort}
placeholder="12345" placeholder="12345"
/> />
<Explainer
text={'You can expose your application to a port on the host system.<br><br>Useful if you would like to use your own reverse proxy or tunnel and also in development mode. Otherwise leave empty.'}
/>
</div> </div>
{/if}
{#if service.type === 'plausibleanalytics'} {#if service.type === 'plausibleanalytics'}
<PlausibleAnalytics bind:service {isRunning} {readOnly} /> <PlausibleAnalytics bind:service {isRunning} {readOnly} />

View File

@ -13,6 +13,7 @@ import { ErrorHandler, getServiceImage } from '$lib/database';
import { makeLabelForServices } from '$lib/buildPacks/common'; import { makeLabelForServices } from '$lib/buildPacks/common';
import type { ComposeFile } from '$lib/types/composeFile'; import type { ComposeFile } from '$lib/types/composeFile';
import type { Service, DestinationDocker, Prisma } from '@prisma/client'; import type { Service, DestinationDocker, Prisma } from '@prisma/client';
import { getServiceMainPort } from '$lib/components/common';
export const post: RequestHandler = async (event) => { export const post: RequestHandler = async (event) => {
const { teamId, status, body } = await getUserDetails(event); const { teamId, status, body } = await getUserDetails(event);
@ -30,6 +31,7 @@ export const post: RequestHandler = async (event) => {
destinationDockerId, destinationDockerId,
destinationDocker, destinationDocker,
serviceSecret, serviceSecret,
exposePort,
fider: { fider: {
postgresqlUser, postgresqlUser,
postgresqlPassword, postgresqlPassword,
@ -48,6 +50,7 @@ export const post: RequestHandler = async (event) => {
} = service; } = service;
const network = destinationDockerId && destinationDocker.network; const network = destinationDockerId && destinationDocker.network;
const host = getEngine(destinationDocker.engine); const host = getEngine(destinationDocker.engine);
const port = getServiceMainPort('fider');
const { workdir } = await createDirectories({ repository: type, buildId: id }); const { workdir } = await createDirectories({ repository: type, buildId: id });
const image = getServiceImage(type); const image = getServiceImage(type);
@ -97,6 +100,7 @@ export const post: RequestHandler = async (event) => {
volumes: [], volumes: [],
restart: 'always', restart: 'always',
labels: makeLabelForServices('fider'), labels: makeLabelForServices('fider'),
...(exposePort ? { ports: [`${exposePort}:${port}`] } : {}),
deploy: { deploy: {
restart_policy: { restart_policy: {
condition: 'on-failure', condition: 'on-failure',

View File

@ -7,6 +7,7 @@ import { ErrorHandler, getServiceImage } from '$lib/database';
import { makeLabelForServices } from '$lib/buildPacks/common'; import { makeLabelForServices } from '$lib/buildPacks/common';
import type { ComposeFile } from '$lib/types/composeFile'; import type { ComposeFile } from '$lib/types/composeFile';
import type { Service, DestinationDocker, Prisma } from '@prisma/client'; import type { Service, DestinationDocker, Prisma } from '@prisma/client';
import { getServiceMainPort } from '$lib/components/common';
export const post: RequestHandler = async (event) => { export const post: RequestHandler = async (event) => {
const { teamId, status, body } = await getUserDetails(event); const { teamId, status, body } = await getUserDetails(event);
@ -23,10 +24,12 @@ export const post: RequestHandler = async (event) => {
destinationDockerId, destinationDockerId,
destinationDocker, destinationDocker,
serviceSecret, serviceSecret,
exposePort,
hasura: { postgresqlUser, postgresqlPassword, postgresqlDatabase } hasura: { postgresqlUser, postgresqlPassword, postgresqlDatabase }
} = service; } = service;
const network = destinationDockerId && destinationDocker.network; const network = destinationDockerId && destinationDocker.network;
const host = getEngine(destinationDocker.engine); const host = getEngine(destinationDocker.engine);
const port = getServiceMainPort('hasura');
const { workdir } = await createDirectories({ repository: type, buildId: id }); const { workdir } = await createDirectories({ repository: type, buildId: id });
const image = getServiceImage(type); const image = getServiceImage(type);
@ -65,6 +68,7 @@ export const post: RequestHandler = async (event) => {
volumes: [], volumes: [],
restart: 'always', restart: 'always',
labels: makeLabelForServices('hasura'), labels: makeLabelForServices('hasura'),
...(exposePort ? { ports: [`${exposePort}:${port}`] } : {}),
deploy: { deploy: {
restart_policy: { restart_policy: {
condition: 'on-failure', condition: 'on-failure',

View File

@ -65,7 +65,7 @@ export const post: RequestHandler = async (event) => {
networks: [network], networks: [network],
volumes: [config.volume], volumes: [config.volume],
restart: 'always', restart: 'always',
...(exposePort && { ports: [`${port}:${port}`] }), ...(exposePort ? { ports: [`${exposePort}:${port}`] } : {}),
labels: makeLabelForServices('minio'), labels: makeLabelForServices('minio'),
deploy: { deploy: {
restart_policy: { restart_policy: {

View File

@ -48,6 +48,7 @@ export const post: RequestHandler = async (event) => {
environment: config.environmentVariables, environment: config.environmentVariables,
restart: 'always', restart: 'always',
labels: makeLabelForServices('n8n'), labels: makeLabelForServices('n8n'),
...(exposePort ? { ports: [`${exposePort}:${port}`] } : {}),
deploy: { deploy: {
restart_policy: { restart_policy: {
condition: 'on-failure', condition: 'on-failure',

View File

@ -135,7 +135,7 @@ COPY ./init-db.sh /docker-entrypoint-initdb.d/init-db.sh`;
networks: [network], networks: [network],
environment: config.plausibleAnalytics.environmentVariables, environment: config.plausibleAnalytics.environmentVariables,
restart: 'always', restart: 'always',
...(exposePort && { ports: [`${port}:${exposePort}`] }), ...(exposePort ? { ports: [`${exposePort}:${port}`] } : {}),
depends_on: [`${id}-postgresql`, `${id}-clickhouse`], depends_on: [`${id}-postgresql`, `${id}-clickhouse`],
labels: makeLabelForServices('plausibleAnalytics'), labels: makeLabelForServices('plausibleAnalytics'),
deploy: { deploy: {
@ -195,6 +195,7 @@ COPY ./init-db.sh /docker-entrypoint-initdb.d/init-db.sh`;
} }
}; };
const composeFileDestination = `${workdir}/docker-compose.yaml`; const composeFileDestination = `${workdir}/docker-compose.yaml`;
console.log(JSON.stringify(composeFile, null, 2));
await fs.writeFile(composeFileDestination, yaml.dump(composeFile)); await fs.writeFile(composeFileDestination, yaml.dump(composeFile));
await asyncExecShell(`DOCKER_HOST=${host} docker compose -f ${composeFileDestination} pull`); await asyncExecShell(`DOCKER_HOST=${host} docker compose -f ${composeFileDestination} pull`);
await asyncExecShell( await asyncExecShell(

View File

@ -159,7 +159,7 @@ export const post: RequestHandler = async (event) => {
networks: [network], networks: [network],
volumes: [], volumes: [],
restart: 'always', restart: 'always',
...(exposePort ? { ports: [`${port}:${port}`] } : {}), ...(exposePort ? { ports: [`${exposePort}:${port}`] } : {}),
labels: makeLabelForServices('umami'), labels: makeLabelForServices('umami'),
deploy: { deploy: {
restart_policy: { restart_policy: {

View File

@ -78,7 +78,7 @@ export const post: RequestHandler = async (event) => {
networks: [network], networks: [network],
volumes: [config.volume, ...volumes], volumes: [config.volume, ...volumes],
restart: 'always', restart: 'always',
...(exposePort ? { ports: [`${port}:${exposePort}`] } : {}), ...(exposePort ? { ports: [`${exposePort}:${port}`] } : {}),
labels: makeLabelForServices('vscodeServer'), labels: makeLabelForServices('vscodeServer'),
deploy: { deploy: {
restart_policy: { restart_policy: {

View File

@ -79,7 +79,7 @@ export const post: RequestHandler = async (event) => {
volumes: [config.wordpress.volume], volumes: [config.wordpress.volume],
networks: [network], networks: [network],
restart: 'always', restart: 'always',
...(exposePort ? { ports: [`${port}:${port}`] } : {}), ...(exposePort ? { ports: [`${exposePort}:${port}`] } : {}),
depends_on: [`${id}-mysql`], depends_on: [`${id}-mysql`],
labels: makeLabelForServices('wordpress'), labels: makeLabelForServices('wordpress'),
deploy: { deploy: {