fix: Expose ports for services
This commit is contained in:
		| @@ -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} | ||||||
|   | |||||||
| @@ -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,32 +160,21 @@ | |||||||
| 					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} | 				<input | ||||||
| 					bind:setting={showExposePort} | 					readonly={!$session.isAdmin && !isRunning} | ||||||
| 					on:click={() => { | 					disabled={!$session.isAdmin || isRunning} | ||||||
| 						showExposePort = !showExposePort; | 					name="exposePort" | ||||||
| 						service.exposePort = undefined; | 					id="exposePort" | ||||||
| 					}} | 					bind:value={service.exposePort} | ||||||
| 					title={$t('application.expose_a_port')} | 					placeholder="12345" | ||||||
| 					description="Expose a port to the host system" | 				/> | ||||||
|  | 				<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 showExposePort} |  | ||||||
| 				<div class="grid grid-cols-2 items-center"> |  | ||||||
| 					<label for="exposePort" class="text-base font-bold text-stone-100">Expose Port</label> |  | ||||||
| 					<input |  | ||||||
| 						readonly={!$session.isAdmin} |  | ||||||
| 						name="exposePort" |  | ||||||
| 						id="exposePort" |  | ||||||
| 						bind:value={service.exposePort} |  | ||||||
| 						placeholder="12345" |  | ||||||
| 					/> |  | ||||||
| 				</div> |  | ||||||
| 			{/if} |  | ||||||
|  |  | ||||||
| 			{#if service.type === 'plausibleanalytics'} | 			{#if service.type === 'plausibleanalytics'} | ||||||
| 				<PlausibleAnalytics bind:service {isRunning} {readOnly} /> | 				<PlausibleAnalytics bind:service {isRunning} {readOnly} /> | ||||||
| 			{:else if service.type === 'minio'} | 			{:else if service.type === 'minio'} | ||||||
|   | |||||||
| @@ -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', | ||||||
|   | |||||||
| @@ -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', | ||||||
|   | |||||||
| @@ -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: { | ||||||
|   | |||||||
| @@ -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', | ||||||
|   | |||||||
| @@ -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( | ||||||
|   | |||||||
| @@ -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: { | ||||||
|   | |||||||
| @@ -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: { | ||||||
|   | |||||||
| @@ -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: { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Andras Bacsai
					Andras Bacsai