Skip to content

Commit

Permalink
Add publication of image for Google Compute Engine (closes #36)
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzhanunlu committed Jun 28, 2018
1 parent dac19f0 commit 209814b
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 24 deletions.
10 changes: 10 additions & 0 deletions Packerfile.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
"Release": "{{user `version`}}"
},
"type": "amazon-ebs"
},
{
"type": "googlecompute",
"image_description": "Snowplow Mini - The Snowplow Pipeline in a box",
"machine_type": "n1-standard-2",
"account_file": "account.json",
"project_id": "engineering-sandbox",
"source_image_family": "ubuntu-1404-lts",
"ssh_username": "ubuntu",
"zone": "us-central1-a"
}
],
"post-processors": [],
Expand Down
7 changes: 6 additions & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ Vagrant.configure("2") do |config|

# Requires Vagrant 1.7.0+
config.push.define "publish", strategy: "local-exec" do |push|
push.script = "vagrant/push.bash"
push.inline = <<-SCRIPT
# comment/uncomment below to enable/disable pushing to AWS
# vagrant/push.bash aws
# comment/uncomment below to enable/disable pushing to GCP
vagrant/push.bash gcp
SCRIPT
end

end
8 changes: 4 additions & 4 deletions provisioning/roles/base/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
- name: Update apt cache
apt: update-cache=yes cache_valid_time=86400
sudo: yes
become: yes

- name: install basic packages
sudo: yes
become: yes
apt: pkg={{ item }} state=latest
tags: [packages]
with_items:
Expand All @@ -15,8 +15,8 @@
lineinfile:
dest="/etc/resolvconf/resolv.conf.d/base"
line="nameserver 8.8.8.8"
sudo: yes
become: yes

- name: Update nameserver list
command: "resolvconf -u"
sudo: yes
become: yes
6 changes: 3 additions & 3 deletions provisioning/roles/docker/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- include_vars: ../../common_vars.yml

- name: Setup the docker repository and install docker
sudo: yes
become: yes
shell: |
apt-get update
apt-get install apt-transport-https ca-certificates curl software-properties-common --yes
Expand All @@ -11,11 +11,11 @@
apt-get update && apt-get install docker-ce --yes
- name: Download docker-compose
sudo: yes
become: yes
shell: curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose

- name: Apply executable permissions to the docker-compose binary
sudo: yes
become: yes
shell: chmod +x /usr/local/bin/docker-compose

- name: Copy docker-compose.yml
Expand Down
6 changes: 3 additions & 3 deletions provisioning/roles/packer/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
- name: Download Packer
sudo: yes
become: yes
shell: curl -o {{ packer_install_dir }}/{{ packer_archive }}.zip {{ packer_url }}

- name: Extract Packer
sudo: yes
become: yes
unarchive: copy=no src={{ packer_install_dir }}/{{ packer_archive }}.zip dest={{ packer_install_dir }}

- name: Remove downloaded packer_archive
sudo: yes
become: yes
shell: "rm -f {{ packer_install_dir }}/{{ packer_archive }}.zip"
2 changes: 1 addition & 1 deletion provisioning/roles/typescript/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: Install Typescript, Browserify and Uglify
command: "{{ item }}"
sudo: yes
become: yes
with_items:
- "npm install -g [email protected]"
- "npm install -g [email protected]"
Expand Down
43 changes: 31 additions & 12 deletions vagrant/push.bash
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,34 @@ cd_root
running=0 && is_running "running"
[ ${running} -eq 1 ] || die "Vagrant guest must be running to push"

# Can't pass args thru vagrant push so have to prompt
read -e -p "Please enter your AWS_ACCESS_KEY_ID: " aws_access_key_id
read -e -p "Please enter your AWS_SECRET_ACCESS_KEY: " aws_secret_access_key

# Build AMI
cmd="export AWS_ACCESS_KEY_ID=$aws_access_key_id && \
export AWS_SECRET_ACCESS_KEY=$aws_secret_access_key && \
cd /vagrant && \
packer build Packerfile.json"
vagrant ssh -c "${cmd}"

exit 0
if [ -z "$1" ]
then
echo "Specify a platform! Aborted."
echo "Usage: push.bash <platform>"
echo "Supported platforms are 'aws', 'gcp'."
exit 1
else
if [ "$1" == "aws" ]
then
# Can't pass args thru vagrant push so have to prompt
read -e -p "Please enter your AWS_ACCESS_KEY_ID: " aws_access_key_id
read -e -p "Please enter your AWS_SECRET_ACCESS_KEY: " aws_secret_access_key

# Build AMI
cmd="export AWS_ACCESS_KEY_ID=$aws_access_key_id && \
export AWS_SECRET_ACCESS_KEY=$aws_secret_access_key && \
cd /vagrant && \
packer build -only=amazon-ebs Packerfile.json"
elif [ "$1" == "gcp" ]
then
echo "GCP uses account.json file to authenticate."
echo "Make sure account.json and Packerfile.json are in same directory!"
cmd="cd /vagrant && \
packer build -only=googlecompute Packerfile.json"
else
echo "Unrecognized platform. Aborted."
exit 1
fi
vagrant ssh -c "${cmd}"
exit 0
fi

0 comments on commit 209814b

Please sign in to comment.