Skip to content

Commit

Permalink
Support use Docker container locally and in Travis CI (#32)
Browse files Browse the repository at this point in the history
* Use gem to replace local utility library.
* Add Dockerfile to run rake build.
* Removed non-system gem packages and update travis ci to use docker container.
* Update the Dockerfile to use environment variable.
* Set ruby version by default to avoid unnecessary warnings due to gemfile.
  • Loading branch information
metacpp authored and dtzar committed Dec 9, 2017
1 parent 178de09 commit 2ffcee5
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ tags
Gemfile.lock

# Test Kitchen files.
.kitchen
.kitchen
50 changes: 13 additions & 37 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,23 @@
# http://about.travis-ci.org/docs/user/build-configuration/
# This file can be validated on:
# http://lint.travis-ci.org/
dist: trusty
sudo: required

language: ruby

rvm:
- 2.3

services:
- docker

env:
global:
- TERRAFORM_VERSION=0.11.1
matrix:
- TERRAFORM_OS_ARCH=linux_amd64
matrix:
include:
- os: linux
env: TERRAFORM_OS_ARCH=linux_amd64
# - os: osx
# env: TERRAFORM_OS_ARCH=darwin_amd64
- TERRAFORM_VERSION=0.11.1 IMAGE_NAME=azure-compute-module

before_install:
# Update Gem.
- gem update --system
- gem --version
# Install GPG for OS X
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew list gpg > /dev/null 2>&1 || brew install gpg; fi
install:
# Import hashicorp's keys.
- curl https://keybase.io/hashicorp/pgp_keys.asc | gpg --import
# Download the binary and signature files.
- curl -Os https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_${TERRAFORM_OS_ARCH}.zip
- curl -Os https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_SHA256SUMS
- curl -Os https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_SHA256SUMS.sig
# Verify the signature file is untampered.
- gpg --verify terraform_${TERRAFORM_VERSION}_SHA256SUMS.sig terraform_${TERRAFORM_VERSION}_SHA256SUMS
# Verify the SHASUM matches the binary.
- shasum -a 256 -c terraform_${TERRAFORM_VERSION}_SHA256SUMS 2>&1 | grep "${TERRAFORM_VERSION}_${TERRAFORM_OS_ARCH}.zip:\sOK"
# Install terraform locally and add into PATH.
- mv terraform_${TERRAFORM_VERSION}_${TERRAFORM_OS_ARCH}.zip terraform.zip
- unzip terraform.zip
- sudo mkdir /usr/local/terraform
- sudo mv terraform /usr/local/terraform
- rm -f terraform && rm -f terraform_hash && rm -f terraform.zip
- export PATH="/usr/local/terraform":$PATH
# Install gems.
- bundle install
# Bake the image.
- docker build -t ${IMAGE_NAME} .

script:
- rake build
# Run the container.
- docker run ${IMAGE_NAME} /bin/sh -c "rake build"
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM microsoft/terraform-test:0.11.1

ENV MODULE_NAME terraform-azurerm-compute

RUN mkdir /usr/src/${MODULE_NAME}
COPY . /usr/src/${MODULE_NAME}

WORKDIR /usr/src/${MODULE_NAME}
RUN ["bundle", "install", "--gemfile", "./Gemfile"]
9 changes: 3 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ ruby "~> 2.3.0"

source 'https://rubygems.org/'

gem 'rake', '~>12.2.0'

group :test do
gem 'colorize', '~>0.8.0'
gem 'kitchen-terraform', '~>3.0.0'
gem 'rspec', '~>3.7.0'
gem 'test-kitchen', '~>1.16.0'
git 'https://github.com/Azure/terramodtest.git' do
gem 'terramodtest', :tag => 'v0.1.0'
end
end
6 changes: 4 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Official gems.
require 'colorize'
require 'rspec/core/rake_task'

require_relative 'build/file_utils'
require_relative 'build/static_utils'
# Git repo gems.
require 'bundler/setup'
require 'terramodtest'

namespace :presteps do
task :clean_up do
Expand Down
15 changes: 0 additions & 15 deletions build/file_utils.rb

This file was deleted.

41 changes: 0 additions & 41 deletions build/static_utils.rb

This file was deleted.

0 comments on commit 2ffcee5

Please sign in to comment.