-
Notifications
You must be signed in to change notification settings - Fork 0
Add deploy-lambdas reusable workflow #5
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
base: main
Are you sure you want to change the base?
Changes from all commits
cd74aed
f7d9461
beea888
62240f6
604ede0
833d40a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| name: Deploy lambdas | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| ENV: | ||
| required: true | ||
| type: string | ||
| SERVICE: | ||
| required: true | ||
| type: string | ||
| secrets: | ||
| SLACK_NOTIFICATION_CI_RUNS: | ||
| required: true | ||
| ACCESS_TOKEN: | ||
| required: true | ||
| AWS_ACCESS_KEY_ID: | ||
| required: true | ||
| AWS_SECRET_ACCESS_KEY: | ||
| required: true | ||
| AWS_DEFAULT_REGION: | ||
| required: true | ||
|
|
||
| jobs: | ||
| deploy: | ||
| name: Deploy Staging Lambdas | ||
| runs-on: ubuntu-latest | ||
| container: | ||
| image: timbru31/node-alpine-git | ||
| env: | ||
| ENV: ${{ inputs.ENV }} | ||
| SERVICE: ${{ inputs.SERVICE }} | ||
| ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} | ||
| AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
| AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
| AWS_DEFAULT_REGION: ${{secrets.AWS_DEFAULT_REGION}} | ||
| SLACK_NOTIFICATION_CI_RUNS: ${{ secrets.SLACK_NOTIFICATION_CI_RUNS }} | ||
| steps: | ||
| - name: Clone repository | ||
| uses: actions/checkout@v2 | ||
| - name: Set NodeJS | ||
| uses: actions/setup-node@v2 | ||
| with: | ||
| node-version-file: .nvmrc | ||
| cache: npm | ||
| - name: 'NPM: Add Config and Authorization' | ||
| run: | | ||
| rm -f .npmrc | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAIK the -f flag means that if it doesn't exist it won't error. Also as I remember I had found that
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right about the |
||
| echo "@emritio:registry=https://npm.pkg.github.com/" > .npmrc | ||
| echo "//npm.pkg.github.com/:_authToken=${PAT}" >> .npmrc | ||
| env: | ||
| PAT: ${{ secrets.ACCESS_TOKEN }} | ||
| # - name: Add git safe directory | ||
| # run: git config --global --add safe.directory /__w/${PWD##*/}/${PWD##*/} | ||
| # - name: Semantic Release | ||
| # uses: cycjimmy/semantic-release-action@v3 | ||
| # env: | ||
| # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| # with: | ||
| # semantic_version: 19 | ||
| # - name: Get previous tag | ||
| # id: previoustag | ||
| # uses: 'WyriHaximus/github-action-get-previous-tag@v1' | ||
| # - name: Set TAG_TO_DEPLOY | ||
| # env: | ||
| # VERSION: ${{ steps.previoustag.outputs.tag }} | ||
| # run: | | ||
| # echo "TAG_TO_DEPLOY=${VERSION}" >> $GITHUB_ENV | ||
| # - name: Checkout tag | ||
| # run: | | ||
| # git checkout tags/${TAG_TO_DEPLOY} | ||
| - name: Configuration | ||
| env: | ||
| AWS_CLI_VERSION: 1.18.101 | ||
| DOCKER_VERSION: 20.10.11-r1 | ||
| run: | | ||
| apk update | ||
| apk add --no-cache curl bash coreutils py3-pip git zip | ||
mateja176 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ln -s /usr/share/zoneinfo/UTC /etc/localtime | ||
| apk add --no-cache docker==${DOCKER_VERSION} | ||
| pip3 install awscli==${AWS_CLI_VERSION} | ||
| - name: Start deployment slack notification | ||
| run: | | ||
| curl -X POST -H 'Content-type: application/json' \ | ||
| --data "{\"text\":\"The $SERVICE service(s) deployment on $ENV environment has begun.\n \"}" \ | ||
| $SLACK_NOTIFICATION_CI_RUNS | ||
mateja176 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - name: Build project | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.PACKAGES_ACCESS_TOKEN }} | ||
| run: | | ||
| rm -rf node_modules | ||
| npm ci | ||
| npm run build | ||
| rm -rf node_modules | ||
| npm ci --only=production --ignore-scripts | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah looks like npm prune --production is a better option for what they're trying to do
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting remark. In summary, since
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additionally, in case that all depdencies, including
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. npm prune didn't work as I expected and we were left with a massive zip
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please reference npm-prune demo. |
||
| - name: Zip code | ||
| run: | | ||
| zip -r event_handler_lambda.zip * | ||
| - name: Update event handler lambda | ||
| run: | | ||
| aws lambda update-function-code --function-name emrit-$ENV-$SERVICE --zip-file fileb://event_handler_lambda.zip --publish | ||
| aws lambda wait function-updated --function-name emrit-$ENV-$SERVICE | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume that you chose
timbru31/node-alpine-gitbecause it based on the official node alpine image with the benefit of having git installed. Do you think that the comfort eliminating theapk install gitis worth it compared to using the official node image which offers more version and is more up to date (as a consequence more secure under some circumstances)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really I just copied it from the other workflow. @thejamespower made the change I believe - what are your thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably better to use the official one and use apk to add git, I was just being lazy