admin管理员组

文章数量:1401425

I want to perform a few terraform tasks in my Gitlab CI but the terragrunt executable is not found. Here is the job:

staging_graphql_terraform_validate:
  stage: validate
  image: alpine/terragrunt:1.3.6
  only:
    - staging
  dependencies:
    - staging_graphql_build_sources
  script:
    - cd $LAMBDA_FROM_S3_TO_GRAPHQL_STAGING_ROOT
    - set -a && source .env && set +a
    - terragrunt init
    - terragrunt validate

And here is the output:

    Running with gitlab-runner 15.7.0~beta.151.gfb1fb1dd (fb1fb1dd)
  on Gitlab runner SSD 7Y_tnzJ9
Preparing the "docker" executor
00:02
Using Docker executor with image alpine/terragrunt:1.3.6 ...
Pulling docker image alpine/terragrunt:1.3.6 ...
Using docker image sha256:90f6e0a08150002555ec8ff494e30f4ee59a88c5b6c5e260b42ee13d2ee4dabd for alpine/terragrunt:1.3.6 with digest alpine/terragrunt@sha256:7c4c0839360376d431c1d036a374d139b2921087d1fac2d9cf2f5aafdb2e9199 ...
Preparing environment
00:01
Running on runner-7ytnzj9-project-32-concurrent-0 via ip-172-31-42-240...
Getting source from Git repository
00:02
Fetching changes with git depth set to 20...
Reinitialized existing Git repository in /builds/infrastructure/live/.git/
Checking out f762fa94 as mag-1608-create-a-ci-to-deploy-new-versions-on-staging-and-prod...
Removing staging/lambda-from-s3-to-graphql/.env
Removing staging/lambda-from-s3-to-graphql/source.zip
Removing staging/lambda-from-s3-to-graphql/src/node_modules/
Removing staging/lambda-from-s3-to-graphql/src/package-lock.json
Skipping Git submodules setup
Downloading artifacts
00:03
Downloading artifacts for staging_graphql_build_sources (56295)...
Downloading artifacts from coordinator... ok        id=56295 responseStatus=200 OK token=glcbt-64
Executing "step_script" stage of the job script
00:01
Using docker image sha256:90f6e0a08150002555ec8ff494e30f4ee59a88c5b6c5e260b42ee13d2ee4dabd for alpine/terragrunt:1.3.6 with digest alpine/terragrunt@sha256:7c4c0839360376d431c1d036a374d139b2921087d1fac2d9cf2f5aafdb2e9199 ...
/bin/bash: line 161: terragrunt: command not found
$ cd $LAMBDA_FROM_S3_TO_GRAPHQL_STAGING_ROOT
$ set -a && source .env && set +a
$ terragrunt init
Cleaning up project directory and file based variables
00:02
ERROR: Job failed: exit code 1

I tried to add export PATH=/usr/local/bin:$PATH in various places without success.

I also successfully ran the job by manually installing everything on an ubuntu:latest image but i need to run terragrunt commands in a lot of jobs and this is very repetitive (I could use a global before_script for that ...) and time consuming.

staging_graphql_terraform_validate:
  stage: validate
  only:
    - staging
  dependencies:
    - staging_graphql_build_sources
  before_script:
    - apt-get update && apt-get install -y wget unzip
    - wget .3.6/terraform_1.3.6_linux_amd64.zip
    - unzip terraform_1.3.6_linux_amd64.zip
    - mv terraform /usr/local/bin/
    - chmod +x /usr/local/bin/terraform
    - wget .42.5/terragrunt_linux_amd64
    - mv terragrunt_linux_amd64 /usr/local/bin/terragrunt
    - chmod +x /usr/local/bin/terragrunt
  script:
    - cd $LAMBDA_FROM_S3_TO_GRAPHQL_STAGING_ROOT
    - set -a && source .env && set +a
    - export PATH=/usr/local/bin:$PATH && terragrunt init && terragrunt validate

本文标签: terraformPATH issue with docker runner in GitlabCIStack Overflow