Skip to content

Commit 41e9f54

Browse files
authored
New deploy way (#12)
1 parent 56fd35e commit 41e9f54

File tree

3 files changed

+128
-1
lines changed

3 files changed

+128
-1
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Manually trigger deploy to staging or production
2+
run-name: "Manually deploy ${{ github.ref_name }} triggered by ${{ github.actor }}; version: ${{ inputs.version }}"
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
version:
8+
description: "Enter the version number"
9+
required: true
10+
default: "main"
11+
environment:
12+
required: false
13+
description: "Select the environment to deploy to"
14+
type: choice
15+
options:
16+
- production
17+
default: production
18+
19+
permissions:
20+
id-token: write
21+
contents: read
22+
23+
jobs:
24+
trigger-production-deploy:
25+
runs-on: ubuntu-latest
26+
if: ${{ github.ref_name == 'main' && inputs.version != '' && inputs.environment == 'production' }}
27+
steps:
28+
- name: Trigger production deploy
29+
uses: neti-filplus-infra/filplus-deploy-action@main
30+
with:
31+
version: ${{ inputs.version }}
32+
environment: production
33+
ecr-repository: provider-sample-url-finder
34+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_IMAGE_DEPLOYER }}
35+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_IMAGE_DEPLOYER }}
36+
aws-region: us-east-1

.github/workflows/publish-new-build.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ on:
1313
description: "Enter the version number"
1414
required: true
1515
default: "latest"
16+
deploy-to-production:
17+
description: "Deploy the new version?"
18+
required: false
19+
type: boolean
20+
default: false
1621

1722
permissions:
1823
contents: write
@@ -70,7 +75,9 @@ jobs:
7075

7176
git-tag:
7277
runs-on: ubuntu-latest
73-
needs: build-and-publish
78+
needs:
79+
- bump-version
80+
- build-and-publish
7481
if: |
7582
${{ github.ref_name == 'main' && inputs.version != '' }} &&
7683
always() &&
@@ -87,3 +94,22 @@ jobs:
8794
TAG_NAME="v${{ inputs.version }}"
8895
git tag $TAG_NAME
8996
git push origin $TAG_NAME
97+
98+
trigger-production-deploy:
99+
runs-on: ubuntu-latest
100+
needs:
101+
- code-check
102+
- bump-version
103+
- build-and-publish
104+
if: ${{ github.ref_name == 'main' && inputs.version != '' && inputs.deploy-to-production == true }}
105+
environment: production-fidl
106+
steps:
107+
- name: Trigger production deploy
108+
uses: neti-filplus-infra/filplus-deploy-action@main
109+
with:
110+
version: ${{ inputs.version }}
111+
environment: production
112+
ecr-repository: provider-sample-url-finder
113+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_IMAGE_DEPLOYER }}
114+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_IMAGE_DEPLOYER }}
115+
aws-region: us-east-1
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
const { execSync } = require("child_process");
2+
3+
const ECR_REPOSITORY = process.env.ECR_REPOSITORY;
4+
const IMAGE_VERSION = process.env.IMAGE_VERSION;
5+
const SSM_PARAMETER_NAME = process.env.SSM_PARAMETER_NAME;
6+
const ENVIRONMENT = process.env.ENVIRONMENT;
7+
8+
if (!ECR_REPOSITORY || !IMAGE_VERSION || !SSM_PARAMETER_NAME) {
9+
console.error(
10+
"Missing environment variables: ECR_REPOSITORY, IMAGE_VERSION, SSM_PARAMETER_NAME"
11+
);
12+
process.exit(1);
13+
}
14+
15+
function runCommand(command) {
16+
try {
17+
const output = execSync(command, { encoding: "utf-8" });
18+
return JSON.parse(output);
19+
} catch (error) {
20+
console.error(`Error running command: ${command}`);
21+
console.error(error.message);
22+
}
23+
}
24+
25+
let currentVersions = runCommand(
26+
`aws ssm get-parameter --name "${SSM_PARAMETER_NAME}" --query "Parameter.Value" --output json`
27+
);
28+
29+
console.log("Current versions:", currentVersions);
30+
31+
if (!currentVersions) {
32+
console.error(
33+
`This app is not supported in this environment: ${ENVIRONMENT}`
34+
);
35+
process.exit(1);
36+
}
37+
38+
console.log("Checking image in ECR...");
39+
40+
const imageExist = runCommand(
41+
`aws ecr-public describe-images --repository-name ${ECR_REPOSITORY} --region us-east-1 --image-ids imageTag=${IMAGE_VERSION}`
42+
);
43+
44+
if (!imageExist || !imageExist.imageDetails) {
45+
console.error(`Image ${IMAGE_VERSION} not found in ECR.`);
46+
process.exit(1);
47+
}
48+
49+
console.log("Image was found in ECR:", imageExist);
50+
console.log("Checking version in SSM...");
51+
52+
const newCurrentSSMParam = IMAGE_VERSION;
53+
54+
console.log("New current SSM params:", newCurrentSSMParam);
55+
56+
try {
57+
const putNewVersion = `aws ssm put-parameter --name "${SSM_PARAMETER_NAME}" --value "${newCurrentSSMParam}" --type String --overwrite`;
58+
59+
execSync(putNewVersion, { stdio: "inherit" });
60+
console.log(`Update version COMPLETE!`);
61+
console.log(`Trigger the deployment process...`);
62+
} catch (error) {
63+
console.error(`Failed to put a new version:`, error.message);
64+
process.exit(1);
65+
}

0 commit comments

Comments
 (0)