Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AB#41638] Add docker username as arg to quick deploy script #166

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 38 additions & 15 deletions scripts/quick-deploy-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ Please follow the service README file to understand how to generate the values,
}
}

function getDockerInfo(): { registry: string; username: string } {
function getDockerInfo(): { registry?: string; username?: string } {
console.log(`\nChecking Docker Info...\n`);

try {
Expand All @@ -190,11 +190,11 @@ function getDockerInfo(): { registry: string; username: string } {

const registry = dockerInfo
.filter((line) => line.startsWith('Registry: '))[0]
.split('Registry: ')[1];
?.split('Registry: ')[1];

const username = dockerInfo
.filter((line) => line.startsWith('Username: '))[0]
.split('Username: ')[1];
?.split('Username: ')[1];

return { registry, username };
} catch (error) {
Expand All @@ -220,13 +220,22 @@ function buildDockerImageAndPush(

execSync(dockerBuildCommand, { stdio: 'inherit' });

const dockerPushCommand = `docker push ${imageTag}`;
try {
const dockerPushCommand = `docker push ${imageTag}`;

console.log(
`\nRunning Docker Push command:\n${chalk.green(dockerPushCommand)}\n`,
);
console.log(
`\nRunning Docker Push command:\n${chalk.green(dockerPushCommand)}\n`,
);

execSync(dockerPushCommand, { stdio: 'inherit' });
execSync(dockerPushCommand, { stdio: 'inherit' });
} catch (error) {
console.log(
`\nError running Docker Push command:\n${chalk.red(
'Please make sure you are logged in to the Docker Hub Registry.',
)}\n`,
);
throw new Error('Unable to push docker image to repository.');
}
}

function buildPiletAndRegister(serviceId: 'media-service'): void {
Expand Down Expand Up @@ -315,6 +324,7 @@ function printAdminPortalURL(serviceDefinitionId: string): void {

async function main(): Promise<void> {
try {
const { username } = getDockerInfo();
const answers = await prompt([
{
type: 'select',
Expand All @@ -326,6 +336,16 @@ async function main(): Promise<void> {
{ title: 'Entitlement Service', value: 'entitlement-service' },
],
},
{
type: 'text',
name: 'dockerUsername',
message: 'Enter the Docker username',
initial: username,
yasithA marked this conversation as resolved.
Show resolved Hide resolved
validate: (value: string) =>
value === undefined || value === ''
? 'A Docker username is required to continue with the deployment. Please provide a value.'
: true,
},
{
type: 'text',
name: 'dockerImageTag',
Expand All @@ -347,24 +367,27 @@ async function main(): Promise<void> {
} else {
const uniqueID = getUniqueID();

const { registry, username } = getDockerInfo();

console.log(`Docker Registry: ${chalk.green(registry)}`);
console.log(`Docker Username: ${chalk.green(username)}`);

validateDeploymentManifestIsModified(answers.serviceId);

const token = await getAccessToken();

await ensureServiceDefinitionExists(token, answers.serviceId, username);
await ensureServiceDefinitionExists(
token,
answers.serviceId,
answers.dockerUsername,
);

const serviceDefinitionId = await getServiceDefinitionID(
token,
answers.serviceId,
);

if (answers.dockerImageTag === '') {
buildDockerImageAndPush(username, answers.serviceId, uniqueID);
buildDockerImageAndPush(
answers.dockerUsername,
answers.serviceId,
uniqueID,
);
} else {
console.log(
`\nUsing the pre-built and pushed docker image [${answers.dockerImageTag}]. Skipping building the backend.`,
Expand Down