Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

terraform - Multiple images as entrypoints for GitLab-ci configuration file

I am writing a gitlab-ci.yml file to build images using packer and thereafter deploy them with terraform. Since I am new to gitlab, I thought it is possible to reference both Terraform and Packer images like so:

image:
 name: registry.gitlab.com/gitlab-org/gitlab-build-images:terraform
 entrypoint:
   - '/usr/bin/env'
   - 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'

image:
  name: hashicorp/packer
  entrypoint:
    - '/usr/bin/env'
    - 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
question from:https://stackoverflow.com/questions/65844444/multiple-images-as-entrypoints-for-gitlab-ci-configuration-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can only have one "default" image that is applied to every step in the pipeline, but you can specify an image to use for each job, or just the jobs that are different from the default.

From the GitLab CI documentation here (https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#define-image-and-services-from-gitlab-ciyml), you can specify a default for all steps to use:

default:
  image: ruby:2.6

  services:
    - postgres:11.7

  before_script:
    - bundle install

test:
  script:
    - bundle exec rake spec

as well as have some steps differ from the default:

default:
  image: ruby:2.6

  services:
    - postgres:11.7

  before_script:
    - bundle install

test: # this uses the default image
  script:
    - bundle exec rake spec

db_setup: # this uses a specific image that is different from the default
  image: mysql:8
  script:
    - mysql -h my_datbase.example.com -u root -ppassword -e "create database my_database"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...