Skip to content

Commit

Permalink
Move deploy to run (#139679)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmrabian authored Jun 27, 2024
1 parent 5d509c7 commit 65e3be1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
run: |
# When deploying multiple copies of this quickstart to the same AWS Account (not ideal), a prefix helps prevent stepping on each other.
# This can optionally be set as an GitHub Actions Secret
./deploy.sh $STAGE_PREFIX$branch_name
./run deploy --stage $STAGE_PREFIX$branch_name
- id: endpoint
run: |
APPLICATION_ENDPOINT=$(./output.sh ui ApplicationEndpointUrl $STAGE_PREFIX$branch_name)
Expand Down
59 changes: 0 additions & 59 deletions deploy.sh

This file was deleted.

57 changes: 57 additions & 0 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ import { execSync } from "child_process";
// load .env
dotenv.config();

const deployedServices = [
"database",
"uploads",
"app-api",
"ui",
"ui-auth",
"ui-src",
];

// Function to update .env files using 1Password CLI
function updateEnvFiles() {
try {
Expand Down Expand Up @@ -117,6 +126,46 @@ async function run_all_locally() {
run_fe_locally(runner);
}

async function deploy_kafka_service(
runner: LabeledProcessRunner,
stage: string
) {
const kafkaservice = "carts-bigmac-streams";
install_deps(runner, kafkaservice);
const kafkaDeployCmd = ["sls", "deploy", "--stage", stage];
await runner.run_command_and_output(
"Kafka service deploy",
kafkaDeployCmd,
`services/${kafkaservice}`
);
}

async function install_deps(runner: LabeledProcessRunner, service: string) {
await runner.run_command_and_output(
"Installing Dependencies",
["yarn", "install", "--frozen-lockfile"],
`services/${service}`
);
}

async function prepare_services(runner: LabeledProcessRunner) {
for (const service of deployedServices) {
install_deps(runner, service);
}
}

async function deploy(options: { stage: string }) {
const stage = options.stage;
const runner = new LabeledProcessRunner();
await prepare_services(runner);
const deployCmd = ["sls", "deploy", "--stage", stage];
await runner.run_command_and_output("SLS Deploy", deployCmd, ".");
// Only deploy resources for kafka ingestion in real envs
if (stage === "main" || stage === "val" || stage === "production") {
deploy_kafka_service(runner, stage);
}
}

async function destroy_stage(options: {
stage: string;
service: string | undefined;
Expand Down Expand Up @@ -153,6 +202,14 @@ yargs(process.argv.slice(2))
run_all_locally();
})
.command("test", "run all tests", () => {})
.command(
"deploy",
"deploy the app with serverless compose to the cloud",
{
stage: { type: "string", demandOption: true },
},
deploy
)
.command(
"destroy",
"destroy serverless stage",
Expand Down

0 comments on commit 65e3be1

Please sign in to comment.