Skip to content

Commit

Permalink
testing custom action
Browse files Browse the repository at this point in the history
  • Loading branch information
Uroš Marolt committed Jan 10, 2024
1 parent 761c142 commit 46abde5
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 37 deletions.
42 changes: 26 additions & 16 deletions .github/actions/node/builder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26472,6 +26472,26 @@ const deployStep = async () => {
core.warning('No services specified for deploy!');
return;
}
// check if any images failed to build
const builderDefinitions = await (0, utils_1.getBuilderDefinitions)();
const servicesToDeploy = [];
for (const service of deployInput.services) {
const builderDef = builderDefinitions.find((b) => b.services.includes(service));
if (!builderDef) {
core.error(`No builder definition found for service: ${service}`);
throw new Error(`No builder definition found for service: ${service}`);
}
if (!imageTagMap.has(builderDef.imageName)) {
core.error(`No tag found for image: ${builderDef.imageName} - image wasn't built successfully!`);
throw new Error(`No tag found for image: ${builderDef.imageName} - image wasn't built successfully!`);
}
const tag = imageTagMap.get(builderDef.imageName);
servicesToDeploy.push({
service,
tag,
builderDef,
});
}
const env = {
AWS_ACCESS_KEY_ID: deployInput.awsAccessKeyId,
AWS_SECRET_ACCESS_KEY: deployInput.awsSecretAccessKey,
Expand All @@ -26491,21 +26511,11 @@ const deployStep = async () => {
core.error('Failed to update kubeconfig!');
throw new Error('Failed to update kubeconfig!');
}
const builderDefinitions = await (0, utils_1.getBuilderDefinitions)();
let failed = [];
for (const service of deployInput.services) {
const builderDefinition = builderDefinitions.find((b) => b.services.includes(service));
if (!builderDefinition) {
core.warning(`No builder definition found for service: ${service}`);
continue;
}
const image = builderDefinition.imageName;
if (!imageTagMap.has(image)) {
core.warning(`No tag found for image: ${image} - image wasn't built successfully!`);
continue;
}
const tag = imageTagMap.get(image);
const prioritized = builderDefinition.prioritizedServices.includes(service);
for (const serviceDef of servicesToDeploy) {
const tag = serviceDef.tag;
const service = serviceDef.service;
const prioritized = serviceDef.builderDef.prioritizedServices.includes(service);
const servicesToUpdate = [];
if (prioritized) {
switch (deployInput.cloudEnvironment) {
Expand All @@ -26530,13 +26540,13 @@ const deployStep = async () => {
else {
servicesToUpdate.push(service);
}
core.info(`Deploying service: ${service} with image: ${builderDefinition.dockerRepository}:${tag} to deployments: ${servicesToUpdate.join(', ')}`);
core.info(`Deploying service: ${service} with image: ${serviceDef.builderDef.dockerRepository}:${tag} to deployments: ${servicesToUpdate.join(', ')}`);
for (const toDeploy of servicesToUpdate) {
exitCode = await exec.exec('kubectl', [
'set',
'image',
`deployments/${toDeploy}-dpl`,
`${toDeploy}=${builderDefinition.dockerRepository}:${tag}`,
`${toDeploy}=${serviceDef.builderDef.dockerRepository}:${tag}`,
]);
if (exitCode !== 0) {
core.error(`Failed to deploy service: ${service} to deployment: ${toDeploy}`);
Expand Down
58 changes: 37 additions & 21 deletions .github/actions/node/src/steps.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getInputs } from './inputs'
import { ActionStep, CloudEnvironment } from './types'
import { ActionStep, CloudEnvironment, IBuilderDefinition } from './types'
import * as core from '@actions/core'
import * as exec from '@actions/exec'
import { getBuilderDefinitions } from './utils'
Expand Down Expand Up @@ -123,6 +123,36 @@ export const deployStep = async (): Promise<void> => {
return
}

// check if any images failed to build
const builderDefinitions = await getBuilderDefinitions()

const servicesToDeploy: { service: string; tag: string; builderDef: IBuilderDefinition }[] = []
for (const service of deployInput.services) {
const builderDef = builderDefinitions.find((b) => b.services.includes(service))

if (!builderDef) {
core.error(`No builder definition found for service: ${service}`)
throw new Error(`No builder definition found for service: ${service}`)
}

if (!imageTagMap.has(builderDef.imageName)) {
core.error(
`No tag found for image: ${builderDef.imageName} - image wasn't built successfully!`,
)
throw new Error(
`No tag found for image: ${builderDef.imageName} - image wasn't built successfully!`,
)
}

const tag = imageTagMap.get(builderDef.imageName)

servicesToDeploy.push({
service,
tag,
builderDef,
})
}

const env = {
AWS_ACCESS_KEY_ID: deployInput.awsAccessKeyId,
AWS_SECRET_ACCESS_KEY: deployInput.awsSecretAccessKey,
Expand All @@ -149,26 +179,12 @@ export const deployStep = async (): Promise<void> => {
throw new Error('Failed to update kubeconfig!')
}

const builderDefinitions = await getBuilderDefinitions()
let failed = []

for (const service of deployInput.services) {
const builderDefinition = builderDefinitions.find((b) => b.services.includes(service))

if (!builderDefinition) {
core.warning(`No builder definition found for service: ${service}`)
continue
}

const image = builderDefinition.imageName
if (!imageTagMap.has(image)) {
core.warning(`No tag found for image: ${image} - image wasn't built successfully!`)
continue
}

const tag = imageTagMap.get(image)

const prioritized = builderDefinition.prioritizedServices.includes(service)
for (const serviceDef of servicesToDeploy) {
const tag = serviceDef.tag
const service = serviceDef.service
const prioritized = serviceDef.builderDef.prioritizedServices.includes(service)
const servicesToUpdate: string[] = []

if (prioritized) {
Expand Down Expand Up @@ -200,7 +216,7 @@ export const deployStep = async (): Promise<void> => {

core.info(
`Deploying service: ${service} with image: ${
builderDefinition.dockerRepository
serviceDef.builderDef.dockerRepository
}:${tag} to deployments: ${servicesToUpdate.join(', ')}`,
)

Expand All @@ -209,7 +225,7 @@ export const deployStep = async (): Promise<void> => {
'set',
'image',
`deployments/${toDeploy}-dpl`,
`${toDeploy}=${builderDefinition.dockerRepository}:${tag}`,
`${toDeploy}=${serviceDef.builderDef.dockerRepository}:${tag}`,
])

if (exitCode !== 0) {
Expand Down

0 comments on commit 46abde5

Please sign in to comment.