@@ -29,7 +29,7 @@ import _ from 'lodash';
2929import { FieldValues , UseFieldArrayAppend , UseFieldArrayRemove } from 'react-hook-form' ;
3030import { formatUnits } from 'viem' ;
3131import { environment } from './config' ;
32- import { deepSort } from './utils' ;
32+ import { deepSort , parseIfJson } from './utils' ;
3333
3434export const GITHUB_REPO_REGEX = new RegExp ( '^https?://github\\.com/([^\\s/]+)/([^\\s/]+?)(?:\\.git)?(?:/.*)?$' , 'i' ) ;
3535
@@ -123,7 +123,7 @@ export const downloadDataAsJson = (data: any, filename: string) => {
123123export const generateDeeployNonce = ( ) : string => {
124124 const now = new Date ( ) ;
125125 const unixTimestamp = now . getTime ( ) ;
126- console . log ( { now, unixTimestamp } ) ;
126+ // console.log({ now, unixTimestamp });
127127 return `0x${ unixTimestamp . toString ( 16 ) } ` ;
128128} ;
129129
@@ -170,10 +170,11 @@ export const formatFileVolumes = (fileVolumes: { name: string; mountingPoint: st
170170 return formatted ;
171171} ;
172172
173- export const formatContainerResources = ( containerOrWorkerType : ContainerOrWorkerType ) => {
173+ export const formatContainerResources = ( containerOrWorkerType : ContainerOrWorkerType , ports ?: Record < string , string > ) => {
174174 return {
175175 cpu : containerOrWorkerType . cores ,
176176 memory : `${ containerOrWorkerType . ram } g` ,
177+ ...( ports && Object . keys ( ports ) . length > 0 && { ports } ) ,
177178 } ;
178179} ;
179180
@@ -208,7 +209,7 @@ export const formatServiceDraftJobPayload = (job: ServiceDraftJob) => {
208209 return formatServiceJobPayload ( containerType , job . specifications , job . deployment ) ;
209210} ;
210211
211- export const formatGenericJobVariables = ( plugin : GenericSecondaryPlugin ) => {
212+ const formatGenericJobVariables = ( plugin : GenericSecondaryPlugin ) => {
212213 return {
213214 envVars : formatEnvVars ( plugin . envVars ) ,
214215 dynamicEnvVars : formatDynamicEnvVars ( plugin . dynamicEnvVars ) ,
@@ -217,16 +218,27 @@ export const formatGenericJobVariables = (plugin: GenericSecondaryPlugin) => {
217218 } ;
218219} ;
219220
220- export const formatNativeJobPluginSignature = ( plugin : NativeSecondaryPlugin ) => {
221+ const formatNativeJobPluginSignature = ( plugin : NativeSecondaryPlugin ) => {
221222 return plugin . pluginSignature === PLUGIN_SIGNATURE_TYPES [ PLUGIN_SIGNATURE_TYPES . length - 1 ]
222223 ? plugin . customPluginSignature
223224 : plugin . pluginSignature ;
224225} ;
225226
227+ const formatNativeJobCustomParams = ( pluginConfig : any , plugin : NativeSecondaryPlugin ) => {
228+ if ( ! _ . isEmpty ( plugin . customParams ) ) {
229+ plugin . customParams . forEach ( ( param ) => {
230+ if ( param . key ) {
231+ pluginConfig [ param . key ] = parseIfJson ( param . value ) ;
232+ }
233+ } ) ;
234+ }
235+ } ;
236+
226237export const formatGenericPluginConfigAndSignature = (
227238 resources : {
228239 cpu : number ;
229240 memory : string ;
241+ ports ?: Record < string , string > ;
230242 } ,
231243 plugin : GenericSecondaryPlugin ,
232244) => {
@@ -291,7 +303,7 @@ export const formatGenericJobPayload = (
291303 const spareNodes = formatNodes ( deployment . spareNodes ) ;
292304
293305 const { pluginConfig, pluginSignature } = formatGenericPluginConfigAndSignature (
294- formatContainerResources ( containerType ) ,
306+ formatContainerResources ( containerType , deployment . deploymentType . ports ) ,
295307 deployment ,
296308 ) ;
297309
@@ -331,7 +343,7 @@ export const formatNativeJobPayload = (
331343 }
332344 } ) ;
333345
334- const nodeResources = formatContainerResources ( workerType ) ;
346+ const nodeResources = formatContainerResources ( workerType , undefined ) ;
335347 const targetNodes = formatNodes ( deployment . targetNodes ) ;
336348 const targetNodesCount = formatTargetNodesCount ( targetNodes , specifications . targetNodesCount ) ;
337349
@@ -348,13 +360,7 @@ export const formatNativeJobPayload = (
348360 NGROK_USE_API : true ,
349361 } ;
350362
351- if ( ! _ . isEmpty ( deployment . customParams ) ) {
352- deployment . customParams . forEach ( ( param ) => {
353- if ( param . key ) {
354- primaryPluginConfig [ param . key ] = param . value ;
355- }
356- } ) ;
357- }
363+ formatNativeJobCustomParams ( primaryPluginConfig , deployment ) ;
358364
359365 // Build plugins array starting with the primary plugin
360366 const plugins = [ primaryPluginConfig ] ;
@@ -424,7 +430,7 @@ export const formatServiceJobPayload = (
424430 deployment : ServiceJobDeployment ,
425431) => {
426432 const jobTags = formatJobTags ( specifications ) ;
427- const containerResources = formatContainerResources ( containerType ) ;
433+ const containerResources = formatContainerResources ( containerType , undefined ) ;
428434 const targetNodes = formatNodes ( deployment . targetNodes ) ;
429435 const spareNodes = formatNodes ( deployment . spareNodes ) ;
430436
0 commit comments