Added expose port for applications

This commit is contained in:
Aaron Styles
2022-04-08 17:12:01 +10:00
parent ca705bbf89
commit 1bd33fea98
12 changed files with 95 additions and 4 deletions

View File

@@ -210,6 +210,7 @@ export async function configureApplication({
name,
fqdn,
port,
exposePort,
installCommand,
buildCommand,
startCommand,
@@ -226,6 +227,7 @@ export async function configureApplication({
buildPack,
fqdn,
port,
exposePort,
installCommand,
buildCommand,
startCommand,

View File

@@ -38,6 +38,7 @@ export default async function (job) {
build_id: buildId,
configHash,
port,
exposePort,
installCommand,
buildCommand,
startCommand,
@@ -143,6 +144,7 @@ export default async function (job) {
JSON.stringify({
buildPack,
port,
exposePort,
installCommand,
buildCommand,
startCommand,
@@ -284,6 +286,7 @@ export default async function (job) {
env_file: envFound ? [`${workdir}/.env`] : [],
networks: [docker.network],
labels: labels,
ports: exposePort ? [`${exposePort}:${port}`] : [],
depends_on: [],
restart: 'always'
}

View File

@@ -4,13 +4,14 @@ import * as db from '$lib/database';
import { ErrorHandler } from '$lib/database';
import type { RequestHandler } from '@sveltejs/kit';
import { promises as dns } from 'dns';
import getPort from 'get-port';
export const post: RequestHandler = async (event) => {
const { status, body } = await getUserDetails(event);
if (status === 401) return { status, body };
const { id } = event.params;
let { fqdn, forceSave } = await event.request.json();
let { exposePort, fqdn, forceSave } = await event.request.json();
fqdn = fqdn.toLowerCase();
try {
@@ -42,6 +43,19 @@ export const post: RequestHandler = async (event) => {
}
}
if (exposePort) {
exposePort = Number(exposePort);
if (exposePort < 1024 || exposePort > 65535) {
throw { message: `Expose Port needs to be between 1024 and 65535` };
}
const publicPort = await getPort({ port: exposePort });
if (exposePort !== publicPort) {
throw { message: `Expose Port ${exposePort} is already in use` };
}
}
return {
status: 200
};

View File

@@ -22,6 +22,7 @@ export const post: RequestHandler = async (event) => {
JSON.stringify({
buildPack: applicationFound.buildPack,
port: applicationFound.port,
exposePort: applicationFound.exposePort,
installCommand: applicationFound.installCommand,
buildCommand: applicationFound.buildCommand,
startCommand: applicationFound.startCommand

View File

@@ -6,6 +6,7 @@ import type { RequestHandler } from '@sveltejs/kit';
import jsonwebtoken from 'jsonwebtoken';
import { get as getRequest } from '$lib/api';
import { setDefaultConfiguration } from '$lib/buildPacks/common';
import getPort from 'get-port';
export const get: RequestHandler = async (event) => {
const { teamId, status, body } = await getUserDetails(event);
@@ -49,6 +50,7 @@ export const post: RequestHandler = async (event) => {
buildPack,
fqdn,
port,
exposePort,
installCommand,
buildCommand,
startCommand,
@@ -59,6 +61,13 @@ export const post: RequestHandler = async (event) => {
pythonVariable
} = await event.request.json();
if (port) port = Number(port);
if (exposePort) {
exposePort = Number(exposePort);
const publicPort = await getPort({ port: exposePort });
if (exposePort !== publicPort) {
exposePort = -1;
}
}
try {
const defaultConfiguration = await setDefaultConfiguration({
@@ -76,6 +85,7 @@ export const post: RequestHandler = async (event) => {
name,
fqdn,
port,
exposePort,
installCommand,
buildCommand,
startCommand,

View File

@@ -125,7 +125,11 @@
async function handleSubmit() {
loading = true;
try {
await post(`/applications/${id}/check.json`, { fqdn: application.fqdn, forceSave });
await post(`/applications/${id}/check.json`, {
fqdn: application.fqdn,
forceSave,
exposePort: application.exposePort
});
await post(`/applications/${id}.json`, { ...application });
return window.location.reload();
} catch ({ error }) {
@@ -326,7 +330,6 @@
bind:value={application.fqdn}
pattern="^https?://([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{'{'}2,{'}'}$"
placeholder="eg: https://coollabs.io"
required
/>
</div>
<div class="grid grid-cols-2 items-center pb-8">
@@ -385,7 +388,18 @@
/>
</div>
{/if}
{#if !staticDeployments.includes(application.buildPack)}
<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={application.exposePort}
placeholder="12345"
/>
</div>
{/if}
{#if !notNodeDeployments.includes(application.buildPack)}
<div class="grid grid-cols-2 items-center">
<label for="installCommand" class="text-base font-bold text-stone-100"

View File

@@ -73,6 +73,7 @@ export const post: RequestHandler = async (event) => {
JSON.stringify({
buildPack: applicationFound.buildPack,
port: applicationFound.port,
exposePort: applicationFound.exposePort,
installCommand: applicationFound.installCommand,
buildCommand: applicationFound.buildCommand,
startCommand: applicationFound.startCommand

View File

@@ -37,6 +37,7 @@ export const post: RequestHandler = async (event) => {
JSON.stringify({
buildPack: applicationFound.buildPack,
port: applicationFound.port,
exposePort: applicationFound.exposePort,
installCommand: applicationFound.installCommand,
buildCommand: applicationFound.buildCommand,
startCommand: applicationFound.startCommand