Created
September 19, 2018 15:52
-
-
Save hpio/30e386aad027db074c732463b13793c7 to your computer and use it in GitHub Desktop.
Gitlab CI configuration for Packer
This file contains hidden or 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
| image: | |
| name: hashicorp/packer:latest | |
| entrypoint: | |
| - '/usr/bin/env' | |
| - 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' | |
| .packer: &packer | |
| before_script: | |
| - packer --version | |
| - mkdir -p ./creds | |
| - eval PROJECT=\$${CI_ENVIRONMENT_NAME}_PROJECT | |
| - eval CREDS=\$${CI_ENVIRONMENT_NAME}_PACKER_SERVICE_KEY | |
| - echo $CREDS | base64 -d > ./creds/credentials.json | |
| - export GOOGLE_APPLICATION_CREDENTIALS=./creds/credentials.json | |
| stages: | |
| - validate | |
| - deploy | |
| validate:dev: | |
| stage: validate | |
| environment: | |
| name: dev | |
| <<: *packer | |
| script: | |
| - find . -maxdepth 1 -name '*.json' -print0 | xargs -t0n1 packer validate -var-file=./params/dev.json | |
| only: | |
| - default | |
| build:dev: | |
| stage: deploy | |
| environment: dev | |
| script: | |
| - find . -maxdepth 1 -name '*.json' -print0 | xargs -t0n1 packer build -var-file=./params/dev.json | |
| only: | |
| - default | |
| when: manual | |
| validate:production: | |
| stage: validate | |
| environment: | |
| name: production | |
| <<: *packer | |
| script: | |
| - find . -maxdepth 1 -name '*.json' -print0 | xargs -t0n1 packer validate -var-file=./params/prod.json | |
| only: | |
| - master | |
| build:production: | |
| stage: deploy | |
| environment: production | |
| <<: *packer | |
| script: | |
| - find . -maxdepth 1 -name '*.json' -print0 | xargs -t0n1 packer build -var-file=./params/prod.json | |
| only: | |
| - master | |
| when: manual |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment