I expected to preset the environment of node and then it installs aws-cdk which will be used for the matrix-ed jobs which are supposed to be an efficient solution for execution.
Here is basically my script:
jobs:
setup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
check-latest: true
cache-dependency-path: package-lock.json # include aws-cdk already
- name: Install AWS CDK
run: 'npm ci'
deploy:
runs-on: ubuntu-latest
needs: [setup]
if: needs.build.result == 'success'
strategy:
matrix:
folder: ${{ fromJSON(needs.detect-changed-files.outputs.matrix) }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
role-to-assume: my-role
role-duration-seconds: 14400 # You can find max duration by following this article, https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use.html#id_roles_use_view-role-max-session
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Deploy Service
working-directory: services/infra
env:
CLOUD_FORMATION_ROLE: my-role
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
run: |
ENV=$(cat ../../artifact.txt)
cdk deploy "*" -c app_name=my-app -c environment=prod -c image=${{env.ECR_REGISTRY}}/${{ matrix.folder }}:prod --require-approval never -r ${{env.CLOUD_FORMATION_ROLE}}
The error trace says: "line 2: cdk: command not found" in the step of "Deploy Service". I have no clue since cdk should have been installed in the setup job.
2
Answers
Jobs are separated task that run in it’s own container/host. could run in parallel. So, you need to install the required sw in each jobs that require it. So try to merge in a single job like:
You have to cache your artifacts between jobs in order to share data. This upload-artifact GitHub Action allows you to cache dependencies between jobs. So, to answer your question you will need to upload your dependency in the "setup" job with the upload-artifact and then, download it in the deploy job with the download-artifact