Added expose port for applications
This commit is contained in:
parent
ca705bbf89
commit
1bd33fea98
@ -29,6 +29,7 @@
|
|||||||
"@sveltejs/adapter-node": "1.0.0-next.73",
|
"@sveltejs/adapter-node": "1.0.0-next.73",
|
||||||
"@sveltejs/kit": "1.0.0-next.303",
|
"@sveltejs/kit": "1.0.0-next.303",
|
||||||
"@types/bcrypt": "5.0.0",
|
"@types/bcrypt": "5.0.0",
|
||||||
|
"@types/dockerode": "^3.3.8",
|
||||||
"@types/js-cookie": "3.0.1",
|
"@types/js-cookie": "3.0.1",
|
||||||
"@types/js-yaml": "4.0.5",
|
"@types/js-yaml": "4.0.5",
|
||||||
"@types/node": "17.0.23",
|
"@types/node": "17.0.23",
|
||||||
|
41
pnpm-lock.yaml
generated
41
pnpm-lock.yaml
generated
@ -7,6 +7,7 @@ specifiers:
|
|||||||
'@sveltejs/adapter-node': 1.0.0-next.73
|
'@sveltejs/adapter-node': 1.0.0-next.73
|
||||||
'@sveltejs/kit': 1.0.0-next.303
|
'@sveltejs/kit': 1.0.0-next.303
|
||||||
'@types/bcrypt': 5.0.0
|
'@types/bcrypt': 5.0.0
|
||||||
|
'@types/dockerode': ^3.3.8
|
||||||
'@types/js-cookie': 3.0.1
|
'@types/js-cookie': 3.0.1
|
||||||
'@types/js-yaml': 4.0.5
|
'@types/js-yaml': 4.0.5
|
||||||
'@types/node': 17.0.23
|
'@types/node': 17.0.23
|
||||||
@ -87,6 +88,7 @@ devDependencies:
|
|||||||
'@sveltejs/adapter-node': 1.0.0-next.73
|
'@sveltejs/adapter-node': 1.0.0-next.73
|
||||||
'@sveltejs/kit': 1.0.0-next.303_svelte@3.46.4
|
'@sveltejs/kit': 1.0.0-next.303_svelte@3.46.4
|
||||||
'@types/bcrypt': 5.0.0
|
'@types/bcrypt': 5.0.0
|
||||||
|
'@types/dockerode': 3.3.8
|
||||||
'@types/js-cookie': 3.0.1
|
'@types/js-cookie': 3.0.1
|
||||||
'@types/js-yaml': 4.0.5
|
'@types/js-yaml': 4.0.5
|
||||||
'@types/node': 17.0.23
|
'@types/node': 17.0.23
|
||||||
@ -505,6 +507,26 @@ packages:
|
|||||||
'@types/responselike': 1.0.0
|
'@types/responselike': 1.0.0
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
/@types/docker-modem/3.0.2:
|
||||||
|
resolution:
|
||||||
|
{
|
||||||
|
integrity: sha512-qC7prjoEYR2QEe6SmCVfB1x3rfcQtUr1n4x89+3e0wSTMQ/KYCyf+/RAA9n2tllkkNc6//JMUZePdFRiGIWfaQ==
|
||||||
|
}
|
||||||
|
dependencies:
|
||||||
|
'@types/node': 17.0.23
|
||||||
|
'@types/ssh2': 0.5.52
|
||||||
|
dev: true
|
||||||
|
|
||||||
|
/@types/dockerode/3.3.8:
|
||||||
|
resolution:
|
||||||
|
{
|
||||||
|
integrity: sha512-/Hip29GzPBWfbSS87lyQDVoB7Ja+kr8oOFWXsySxNFa7jlyj3Yws8LaZRmn1xZl7uJH3Xxsg0oI09GHpT1pIBw==
|
||||||
|
}
|
||||||
|
dependencies:
|
||||||
|
'@types/docker-modem': 3.0.2
|
||||||
|
'@types/node': 17.0.23
|
||||||
|
dev: true
|
||||||
|
|
||||||
/@types/http-cache-semantics/4.0.1:
|
/@types/http-cache-semantics/4.0.1:
|
||||||
resolution:
|
resolution:
|
||||||
{
|
{
|
||||||
@ -589,6 +611,25 @@ packages:
|
|||||||
'@types/node': 17.0.23
|
'@types/node': 17.0.23
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/@types/ssh2-streams/0.1.9:
|
||||||
|
resolution:
|
||||||
|
{
|
||||||
|
integrity: sha512-I2J9jKqfmvXLR5GomDiCoHrEJ58hAOmFrekfFqmCFd+A6gaEStvWnPykoWUwld1PNg4G5ag1LwdA+Lz1doRJqg==
|
||||||
|
}
|
||||||
|
dependencies:
|
||||||
|
'@types/node': 17.0.23
|
||||||
|
dev: true
|
||||||
|
|
||||||
|
/@types/ssh2/0.5.52:
|
||||||
|
resolution:
|
||||||
|
{
|
||||||
|
integrity: sha512-lbLLlXxdCZOSJMCInKH2+9V/77ET2J6NPQHpFI0kda61Dd1KglJs+fPQBchizmzYSOJBgdTajhPqBO1xxLywvg==
|
||||||
|
}
|
||||||
|
dependencies:
|
||||||
|
'@types/node': 17.0.23
|
||||||
|
'@types/ssh2-streams': 0.1.9
|
||||||
|
dev: true
|
||||||
|
|
||||||
/@typescript-eslint/eslint-plugin/4.31.1_8ede7edd7694646e12d33c52460f622c:
|
/@typescript-eslint/eslint-plugin/4.31.1_8ede7edd7694646e12d33c52460f622c:
|
||||||
resolution:
|
resolution:
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Application" ADD COLUMN "exposePort" INTEGER;
|
@ -81,6 +81,7 @@ model Application {
|
|||||||
buildPack String?
|
buildPack String?
|
||||||
projectId Int?
|
projectId Int?
|
||||||
port Int?
|
port Int?
|
||||||
|
exposePort Int?
|
||||||
installCommand String?
|
installCommand String?
|
||||||
buildCommand String?
|
buildCommand String?
|
||||||
startCommand String?
|
startCommand String?
|
||||||
|
@ -210,6 +210,7 @@ export async function configureApplication({
|
|||||||
name,
|
name,
|
||||||
fqdn,
|
fqdn,
|
||||||
port,
|
port,
|
||||||
|
exposePort,
|
||||||
installCommand,
|
installCommand,
|
||||||
buildCommand,
|
buildCommand,
|
||||||
startCommand,
|
startCommand,
|
||||||
@ -226,6 +227,7 @@ export async function configureApplication({
|
|||||||
buildPack,
|
buildPack,
|
||||||
fqdn,
|
fqdn,
|
||||||
port,
|
port,
|
||||||
|
exposePort,
|
||||||
installCommand,
|
installCommand,
|
||||||
buildCommand,
|
buildCommand,
|
||||||
startCommand,
|
startCommand,
|
||||||
|
@ -38,6 +38,7 @@ export default async function (job) {
|
|||||||
build_id: buildId,
|
build_id: buildId,
|
||||||
configHash,
|
configHash,
|
||||||
port,
|
port,
|
||||||
|
exposePort,
|
||||||
installCommand,
|
installCommand,
|
||||||
buildCommand,
|
buildCommand,
|
||||||
startCommand,
|
startCommand,
|
||||||
@ -143,6 +144,7 @@ export default async function (job) {
|
|||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
buildPack,
|
buildPack,
|
||||||
port,
|
port,
|
||||||
|
exposePort,
|
||||||
installCommand,
|
installCommand,
|
||||||
buildCommand,
|
buildCommand,
|
||||||
startCommand,
|
startCommand,
|
||||||
@ -284,6 +286,7 @@ export default async function (job) {
|
|||||||
env_file: envFound ? [`${workdir}/.env`] : [],
|
env_file: envFound ? [`${workdir}/.env`] : [],
|
||||||
networks: [docker.network],
|
networks: [docker.network],
|
||||||
labels: labels,
|
labels: labels,
|
||||||
|
ports: exposePort ? [`${exposePort}:${port}`] : [],
|
||||||
depends_on: [],
|
depends_on: [],
|
||||||
restart: 'always'
|
restart: 'always'
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,14 @@ import * as db from '$lib/database';
|
|||||||
import { ErrorHandler } from '$lib/database';
|
import { ErrorHandler } from '$lib/database';
|
||||||
import type { RequestHandler } from '@sveltejs/kit';
|
import type { RequestHandler } from '@sveltejs/kit';
|
||||||
import { promises as dns } from 'dns';
|
import { promises as dns } from 'dns';
|
||||||
|
import getPort from 'get-port';
|
||||||
|
|
||||||
export const post: RequestHandler = async (event) => {
|
export const post: RequestHandler = async (event) => {
|
||||||
const { status, body } = await getUserDetails(event);
|
const { status, body } = await getUserDetails(event);
|
||||||
if (status === 401) return { status, body };
|
if (status === 401) return { status, body };
|
||||||
|
|
||||||
const { id } = event.params;
|
const { id } = event.params;
|
||||||
let { fqdn, forceSave } = await event.request.json();
|
let { exposePort, fqdn, forceSave } = await event.request.json();
|
||||||
fqdn = fqdn.toLowerCase();
|
fqdn = fqdn.toLowerCase();
|
||||||
|
|
||||||
try {
|
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 {
|
return {
|
||||||
status: 200
|
status: 200
|
||||||
};
|
};
|
||||||
|
@ -22,6 +22,7 @@ export const post: RequestHandler = async (event) => {
|
|||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
buildPack: applicationFound.buildPack,
|
buildPack: applicationFound.buildPack,
|
||||||
port: applicationFound.port,
|
port: applicationFound.port,
|
||||||
|
exposePort: applicationFound.exposePort,
|
||||||
installCommand: applicationFound.installCommand,
|
installCommand: applicationFound.installCommand,
|
||||||
buildCommand: applicationFound.buildCommand,
|
buildCommand: applicationFound.buildCommand,
|
||||||
startCommand: applicationFound.startCommand
|
startCommand: applicationFound.startCommand
|
||||||
|
@ -6,6 +6,7 @@ import type { RequestHandler } from '@sveltejs/kit';
|
|||||||
import jsonwebtoken from 'jsonwebtoken';
|
import jsonwebtoken from 'jsonwebtoken';
|
||||||
import { get as getRequest } from '$lib/api';
|
import { get as getRequest } from '$lib/api';
|
||||||
import { setDefaultConfiguration } from '$lib/buildPacks/common';
|
import { setDefaultConfiguration } from '$lib/buildPacks/common';
|
||||||
|
import getPort from 'get-port';
|
||||||
|
|
||||||
export const get: RequestHandler = async (event) => {
|
export const get: RequestHandler = async (event) => {
|
||||||
const { teamId, status, body } = await getUserDetails(event);
|
const { teamId, status, body } = await getUserDetails(event);
|
||||||
@ -49,6 +50,7 @@ export const post: RequestHandler = async (event) => {
|
|||||||
buildPack,
|
buildPack,
|
||||||
fqdn,
|
fqdn,
|
||||||
port,
|
port,
|
||||||
|
exposePort,
|
||||||
installCommand,
|
installCommand,
|
||||||
buildCommand,
|
buildCommand,
|
||||||
startCommand,
|
startCommand,
|
||||||
@ -59,6 +61,13 @@ export const post: RequestHandler = async (event) => {
|
|||||||
pythonVariable
|
pythonVariable
|
||||||
} = await event.request.json();
|
} = await event.request.json();
|
||||||
if (port) port = Number(port);
|
if (port) port = Number(port);
|
||||||
|
if (exposePort) {
|
||||||
|
exposePort = Number(exposePort);
|
||||||
|
const publicPort = await getPort({ port: exposePort });
|
||||||
|
if (exposePort !== publicPort) {
|
||||||
|
exposePort = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const defaultConfiguration = await setDefaultConfiguration({
|
const defaultConfiguration = await setDefaultConfiguration({
|
||||||
@ -76,6 +85,7 @@ export const post: RequestHandler = async (event) => {
|
|||||||
name,
|
name,
|
||||||
fqdn,
|
fqdn,
|
||||||
port,
|
port,
|
||||||
|
exposePort,
|
||||||
installCommand,
|
installCommand,
|
||||||
buildCommand,
|
buildCommand,
|
||||||
startCommand,
|
startCommand,
|
||||||
|
@ -125,7 +125,11 @@
|
|||||||
async function handleSubmit() {
|
async function handleSubmit() {
|
||||||
loading = true;
|
loading = true;
|
||||||
try {
|
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 });
|
await post(`/applications/${id}.json`, { ...application });
|
||||||
return window.location.reload();
|
return window.location.reload();
|
||||||
} catch ({ error }) {
|
} catch ({ error }) {
|
||||||
@ -326,7 +330,6 @@
|
|||||||
bind:value={application.fqdn}
|
bind:value={application.fqdn}
|
||||||
pattern="^https?://([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{'{'}2,{'}'}$"
|
pattern="^https?://([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{'{'}2,{'}'}$"
|
||||||
placeholder="eg: https://coollabs.io"
|
placeholder="eg: https://coollabs.io"
|
||||||
required
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="grid grid-cols-2 items-center pb-8">
|
<div class="grid grid-cols-2 items-center pb-8">
|
||||||
@ -385,7 +388,18 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/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)}
|
{#if !notNodeDeployments.includes(application.buildPack)}
|
||||||
<div class="grid grid-cols-2 items-center">
|
<div class="grid grid-cols-2 items-center">
|
||||||
<label for="installCommand" class="text-base font-bold text-stone-100"
|
<label for="installCommand" class="text-base font-bold text-stone-100"
|
||||||
|
@ -73,6 +73,7 @@ export const post: RequestHandler = async (event) => {
|
|||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
buildPack: applicationFound.buildPack,
|
buildPack: applicationFound.buildPack,
|
||||||
port: applicationFound.port,
|
port: applicationFound.port,
|
||||||
|
exposePort: applicationFound.exposePort,
|
||||||
installCommand: applicationFound.installCommand,
|
installCommand: applicationFound.installCommand,
|
||||||
buildCommand: applicationFound.buildCommand,
|
buildCommand: applicationFound.buildCommand,
|
||||||
startCommand: applicationFound.startCommand
|
startCommand: applicationFound.startCommand
|
||||||
|
@ -37,6 +37,7 @@ export const post: RequestHandler = async (event) => {
|
|||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
buildPack: applicationFound.buildPack,
|
buildPack: applicationFound.buildPack,
|
||||||
port: applicationFound.port,
|
port: applicationFound.port,
|
||||||
|
exposePort: applicationFound.exposePort,
|
||||||
installCommand: applicationFound.installCommand,
|
installCommand: applicationFound.installCommand,
|
||||||
buildCommand: applicationFound.buildCommand,
|
buildCommand: applicationFound.buildCommand,
|
||||||
startCommand: applicationFound.startCommand
|
startCommand: applicationFound.startCommand
|
||||||
|
Loading…
x
Reference in New Issue
Block a user