forked from terraform-compliance/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.travis.yml
83 lines (78 loc) · 3.74 KB
/
.travis.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
language: python
python:
- '3.6'
services:
- docker
cache:
pip: true
env:
global:
- IMAGE_NAME=eerkunt/terraform-compliance
addons:
sonarcloud:
organization: "eerkunt-github"
token:
secure: $SONAR_TOKEN
install:
- pip install coveralls
- pip install -r requirements.txt
- pip install jinja2-cli tox
after_success: coveralls
jobs:
include:
- stage: Unit Tests
provider: script
script:
- py.test -v
- coverage run --source terraform_compliance setup.py test
- echo "Current tag is $TRAVIS_TAG"
- stage: Integration Tests
provider: script
script:
- tox -e integration
- stage: Build & Deploy (PYPI)
script:
- echo "PYPI Build & Deploy"
- echo "Current tag is $TRAVIS_TAG"
- jinja2 -D VERSION=$TRAVIS_TAG terraform_compliance/__init__.py -o terraform_compliance/__init__.py.templated
- cat terraform_compliance/__init__.py.templated
- cp terraform_compliance/__init__.py.templated terraform_compliance/__init__.py
- echo "export RELEASE_VERSION=$(cat /home/travis/build/eerkunt/terraform-compliance/terraform_compliance/__init__.py | grep __version__ | cut -d "'" -f2)" > reqs.sh
- source reqs.sh
- if [[ "$TRAVIS_TAG" != "$RELEASE_VERSION" ]]; then echo "TRAVIS_TAG ($TRAVIS_TAG) does not match with RELEASE_VERSION ($RELEASE_VERSION)"; travis_terminate 1; fi
- python setup.py install_egg_info
if: tag IS present
deploy:
skip_cleanup: true
provider: pypi
user: $PYPI_USER
password: $PYPI_PASS
distributions: "sdist bdist_wheel"
on:
tags: true
fork: false
- stage: Build & Deploy (Docker)
provider: script
if: tag IS present
script:
- echo "Docker Build & Deploy"
- echo "Validating the version with the tag"
- echo "Current tag is $TRAVIS_TAG"
- jinja2 -D VERSION=$TRAVIS_TAG terraform_compliance/__init__.py -o terraform_compliance/__init__.py.templated
- cat terraform_compliance/__init__.py.templated
- cp terraform_compliance/__init__.py.templated terraform_compliance/__init__.py
- echo "export RELEASE_VERSION=$(cat /home/travis/build/eerkunt/terraform-compliance/terraform_compliance/__init__.py | grep __version__ | cut -d "'" -f2)" > reqs.sh
- source reqs.sh
- if [[ "$TRAVIS_TAG" != "$RELEASE_VERSION" ]]; then echo "TRAVIS_TAG ($TRAVIS_TAG) does not match with RELEASE_VERSION ($RELEASE_VERSION)"; travis_terminate 1; fi
- if [ -z "$RELEASE_VERSION" ]; then echo "Can not identify the version!"; travis_terminate 1; fi
- echo "Getting the latest terraform version from Hashicorp"
- echo "export LATEST_TERRAFORM_VERSION=$(curl https://checkpoint-api.hashicorp.com/v1/check/terraform | jq -r .current_version)" > terraform_version.sh
- source terraform_version.sh
- if [ -z "$LATEST_TERRAFORM_VERSION" ]; then echo "Can not identify latest terraform version!"; travis_terminate 1; fi
- travis_retry docker build --compress --no-cache -t "$IMAGE_NAME" --build-arg VERSION=$RELEASE_VERSION --build-arg LATEST_TERRAFORM_VERSION=$LATEST_TERRAFORM_VERSION --build-arg HASHICORP_PGP_KEY="$(cat hashicorp-pgp-key.pub)" . || travis_terminate 1
- docker images || travis_terminate 1
- docker login -u "$DOCKER_HUB_USER" -p "$DOCKER_HUB_PASS" || travis_terminate 1
- docker tag "$IMAGE_NAME" eerkunt/terraform-compliance:latest || travis_terminate 1
- docker tag "$IMAGE_NAME" "$IMAGE_NAME":"$RELEASE_VERSION" || travis_terminate 1
- docker push "$IMAGE_NAME":latest || travis_terminate 1
- docker push "$IMAGE_NAME":"$RELEASE_VERSION" || travis_terminate 1