-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEVPROD-5375: Add staging and beta deploy tasks to Evergreen (#177)
- Loading branch information
Showing
26 changed files
with
381 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
functions: | ||
setup-credentials: | ||
command: shell.exec | ||
params: | ||
working_dir: ui/apps/${app_to_deploy} | ||
env: | ||
BUCKET: ${bucket_arg} | ||
NEW_RELIC_ACCOUNT_ID: ${NEW_RELIC_ACCOUNT_ID} | ||
NEW_RELIC_LICENSE_KEY: ${NEW_RELIC_LICENSE_KEY} | ||
NEW_RELIC_TRUST_KEY: ${NEW_RELIC_TRUST_KEY} | ||
PARSLEY_NEW_RELIC_AGENT_ID: ${PARSLEY_NEW_RELIC_AGENT_ID} | ||
PARSLEY_NEW_RELIC_APPLICATION_ID: ${PARSLEY_NEW_RELIC_APPLICATION_ID} | ||
PARSLEY_SENTRY_AUTH_TOKEN: ${PARSLEY_SENTRY_AUTH_TOKEN} | ||
REACT_APP_PARSLEY_SENTRY_DSN: ${REACT_APP_PARSLEY_SENTRY_DSN} | ||
REACT_APP_SPRUCE_SENTRY_DSN: ${REACT_APP_SPRUCE_SENTRY_DSN} | ||
SPRUCE_NEW_RELIC_AGENT_ID: ${SPRUCE_NEW_RELIC_AGENT_ID} | ||
SPRUCE_NEW_RELIC_APPLICATION_ID: ${SPRUCE_NEW_RELIC_APPLICATION_ID} | ||
SPRUCE_SENTRY_AUTH_TOKEN: ${SPRUCE_SENTRY_AUTH_TOKEN} | ||
script: | | ||
${PREPARE_SHELL} | ||
PWD=$(pwd) yarn ts-node -e "import {setupCredentials} from '@evg-ui/deploy-utils'; setupCredentials(\"$PWD\", \"${target}\");" | ||
deploy: | ||
command: shell.exec | ||
params: | ||
working_dir: ui/apps/${app_to_deploy} | ||
env: | ||
BUCKET: ${bucket_arg} | ||
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID} | ||
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY} | ||
AWS_SESSION_TOKEN: ${AWS_SESSION_TOKEN} | ||
script: | | ||
${PREPARE_SHELL} | ||
yarn env-cmd -e ${target} ts-node -e "import {deployRemote} from '@evg-ui/deploy-utils'; deployRemote();" | ||
tasks: | ||
- name: deploy-parsley-staging | ||
commands: | ||
- func: setup-credentials | ||
vars: | ||
app_to_deploy: parsley | ||
bucket_arg: ${parsley_bucket_staging} | ||
target: staging | ||
- func: symlink | ||
vars: | ||
app_dir: apps/parsley | ||
- func: deploy | ||
vars: | ||
app_to_deploy: parsley | ||
bucket_arg: ${parsley_bucket_staging} | ||
target: staging | ||
- name: deploy-parsley-beta | ||
commands: | ||
- func: setup-credentials | ||
vars: | ||
app_to_deploy: parsley | ||
bucket_arg: ${parsley_bucket_beta} | ||
target: beta | ||
- func: symlink | ||
vars: | ||
app_dir: apps/parsley | ||
- func: deploy | ||
vars: | ||
app_to_deploy: parsley | ||
bucket_arg: ${parsley_bucket_beta} | ||
target: beta | ||
- name: deploy-spruce-staging | ||
commands: | ||
- func: setup-credentials | ||
vars: | ||
app_to_deploy: spruce | ||
bucket_arg: ${spruce_bucket_staging} | ||
target: staging | ||
- func: symlink | ||
vars: | ||
app_dir: apps/spruce | ||
- func: deploy | ||
vars: | ||
app_to_deploy: spruce | ||
bucket_arg: ${spruce_bucket_staging} | ||
target: staging | ||
- name: deploy-spruce-beta | ||
commands: | ||
- func: setup-credentials | ||
vars: | ||
app_to_deploy: spruce | ||
bucket_arg: ${spruce_bucket_beta} | ||
target: beta | ||
- func: symlink | ||
vars: | ||
app_dir: apps/spruce | ||
- func: deploy | ||
vars: | ||
app_to_deploy: spruce | ||
bucket_arg: ${spruce_bucket_beta} | ||
target: beta |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
node_modules | ||
|
||
.env-cmdrc.json | ||
|
||
# artifacts | ||
bin | ||
build | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
extends: ["@evg-ui"], | ||
root: true, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import baseConfig from "@evg-ui/lint-staged"; | ||
|
||
export default baseConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "@evg-ui/deploy-utils", | ||
"version": "0.0.0", | ||
"private": true, | ||
"main": "src/index.ts", | ||
"scripts": { | ||
"check-types": "tsc -p tsconfig.json --noEmit", | ||
"eslint:fix": "yarn eslint:strict --fix", | ||
"eslint:staged": "STRICT=1 eslint", | ||
"eslint:strict": "STRICT=1 eslint .", | ||
"test": "vitest --typecheck=false" | ||
}, | ||
"dependencies": { | ||
"@evg-ui/lib": "*" | ||
}, | ||
"devDependencies": { | ||
"@evg-ui/eslint-config": "*", | ||
"@types/node": "^20.12.7", | ||
"eslint": "8.56.0", | ||
"eslint-plugin-prettier": "5.1.3", | ||
"typescript": "5.1.3", | ||
"vitest": "1.6.0" | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
packages/deploy-utils/src/deploy-remote/deploy-remote.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { mockEnvironmentVariables } from "@evg-ui/lib/test_utils/utils"; | ||
import { execSync } from "child_process"; | ||
import { deployRemote } from "."; | ||
import { pushToS3 } from "../utils/s3"; | ||
|
||
const { cleanup, mockEnv } = mockEnvironmentVariables(); | ||
|
||
vi.mock("child_process", () => ({ | ||
execSync: vi.fn(), | ||
})); | ||
|
||
vi.mock("../utils/s3", () => ({ | ||
pushToS3: vi.fn(), | ||
})); | ||
|
||
describe("remote deploys", () => { | ||
afterEach(() => { | ||
vi.restoreAllMocks(); | ||
cleanup(); | ||
}); | ||
|
||
it("fails when no bucket env var exists", () => { | ||
expect(() => deployRemote()).toThrowError("No bucket specified"); | ||
expect(vi.mocked(pushToS3)).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("calls pushToS3 function when BUCKET is defined", () => { | ||
mockEnv("BUCKET", "bucket-name"); | ||
deployRemote(); | ||
expect(vi.mocked(pushToS3)).toHaveBeenCalledOnce(); | ||
expect(vi.mocked(pushToS3)).toHaveBeenCalledWith("bucket-name"); | ||
}); | ||
|
||
it("fails when yarn build fails", () => { | ||
vi.mocked(execSync).mockImplementation(() => { | ||
throw Error("mock yarn build error"); | ||
}); | ||
expect(() => deployRemote()).toThrowError("mock yarn build error"); | ||
expect(vi.mocked(pushToS3)).not.toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { execSync } from "child_process"; | ||
import { pushToS3 } from "../utils/s3"; | ||
|
||
export const deployRemote = () => { | ||
execSync("yarn build", { stdio: "inherit" }); | ||
|
||
if (process.env.BUCKET) { | ||
pushToS3(process.env.BUCKET); | ||
} else { | ||
throw Error("No bucket specified."); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { setupCredentials } from "./utils/setup-credentials"; | ||
export { pushToS3 } from "./utils/s3"; | ||
export { deployRemote } from "./deploy-remote"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { execSync } from "child_process"; | ||
|
||
export const pushToS3 = (bucket: string) => { | ||
console.log("Attempting to deploy to S3"); | ||
try { | ||
execSync( | ||
`aws s3 sync dist/ s3://"${bucket}"/ --acl public-read --follow-symlinks --delete --exclude .env-cmdrc.json`, | ||
{ stdio: "inherit" }, | ||
); | ||
console.log("Successfully deployed to S3"); | ||
} catch (e) { | ||
throw Error("Deployment to S3 failed", { cause: e }); | ||
} | ||
}; |
Oops, something went wrong.