From 9139b5231e0c75882c750d5ac70f8d6f13c92a47 Mon Sep 17 00:00:00 2001 From: Miranda Wilson Date: Tue, 7 Sep 2021 13:11:38 +0100 Subject: [PATCH] Replace Vagrant with Docker (closes #118) --- .dockerignore | 9 +++++ Dockerfile | 9 +++++ README.md | 55 ++++++++++++---------------- Vagrantfile | 23 ------------ snowplow-tracker.gemspec | 6 +-- vagrant/.gitignore | 3 -- vagrant/ansible.hosts | 2 - vagrant/peru.yaml | 14 ------- vagrant/push.bash | 79 ---------------------------------------- vagrant/up.bash | 50 ------------------------- vagrant/up.guidance | 6 --- vagrant/up.playbooks | 1 - 12 files changed, 43 insertions(+), 214 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile delete mode 100644 Vagrantfile delete mode 100644 vagrant/.gitignore delete mode 100644 vagrant/ansible.hosts delete mode 100644 vagrant/peru.yaml delete mode 100755 vagrant/push.bash delete mode 100755 vagrant/up.bash delete mode 100644 vagrant/up.guidance delete mode 100644 vagrant/up.playbooks diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9b2dbb6 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +.git +.gitignore + +.DS_Store +.vscode/ +coverage/ + +.gem +Gemfile.lock diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ef80a5f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM ruby:2.6 + +WORKDIR /code + +COPY ./ ./ +RUN gem install bundler +RUN bundle install + +CMD ["rspec"] diff --git a/README.md b/README.md index f3db48b..e87e06e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Ruby Analytics for Snowplow -[![early-release]][tracker-classificiation] +[![early-release]][tracker-classification] [![Gem Version](https://badge.fury.io/rb/snowplow-tracker.svg)](https://badge.fury.io/rb/snowplow-tracker) [![Build Status](https://travis-ci.org/snowplow/snowplow-ruby-tracker.png?branch=master)](https://travis-ci.org/snowplow/snowplow-ruby-tracker) [![Code Climate](https://codeclimate.com/github/snowplow/snowplow-ruby-tracker.png)](https://codeclimate.com/github/snowplow/snowplow-ruby-tracker) @@ -13,32 +13,34 @@ Add analytics to your Ruby and Rails apps and gems with the **[Snowplow][snowplo With this tracker you can collect event data from your **[Ruby][ruby]** applications, **[Ruby on Rails][rails]** web applications and **[Ruby gems][rubygems]**. -## Quickstart +## Maintainer Quickstart -Assuming git, **[Vagrant][vagrant-install]** and **[VirtualBox][virtualbox-install]** installed: +Clone this repo and navigate into the cloned folder. To run the tests locally, you will need [Docker][docker] installed. ```bash - host$ git clone https://github.com/snowplow/snowplow-ruby-tracker.git - host$ cd snowplow-ruby-tracker - host$ vagrant up && vagrant ssh -guest$ cd /vagrant -guest$ gem install bundler -guest$ bundle install -guest$ rspec +docker build . -t ruby-tracker +docker run -v "$(pwd)":"/code" ruby-tracker ``` -## Publishing +The `-v` flag for `docker run` creates a bind mount for the project directory. This means that changes to the files will be automatically applied within the Docker image. However, if you modify the `Gemfile` or `snowplow-tracker.gemspec` files, the image must be rebuilt. -```bash - host$ vagrant push +Alternatively, test directly by installing Ruby 2.6+ and [Bundler][bundler]. Then run: + +``` +bundle install +rspec ``` +## Contributing + +Feedback and contributions are welcome - if you have identified a bug, please log an issue on this repo. For all other feedback, discussion or questions please open a thread on our [Discourse forum][discourse]. + ## Find out more -| Technical Docs | Setup Guide | Roadmap | Contributing | -|---------------------------------|---------------------------|-------------------------|-----------------------------------| -| ![i1][techdocs-image] | ![i2][setup-image] | ![i3][roadmap-image] | ![i4][contributing-image] | -| **[Technical Docs][techdocs]** | **[Setup Guide][setup]** | **[Roadmap][roadmap]** | **[Contributing](Contributing.md)** | +| Technical Docs | Contributing | +| ------------------------------ | ----------------------------------- | +| ![i1][techdocs-image] | ![i4][contributing-image] | +| **[Technical Docs][techdocs]** | **[Contributing](Contributing.md)** | ## Copyright and license @@ -55,24 +57,15 @@ limitations under the License. [license-image]: https://img.shields.io/badge/license-Apache--2-blue.svg?style=flat [license]: https://www.apache.org/licenses/LICENSE-2.0 - [ruby]: https://www.ruby-lang.org/en/ [rails]: https://rubyonrails.org/ [rubygems]: https://rubygems.org/ - +[docker]: https://www.docker.com/ +[bundler]: https://bundler.io/ [snowplow]: httpd://snowplowanalytics.com - -[vagrant-install]: https://docs.vagrantup.com/v2/installation -[virtualbox-install]: https://www.virtualbox.org/wiki/Downloads - +[discourse]: https://discourse.snowplowanalytics.com [techdocs-image]: https://d3i6fms1cm1j0i.cloudfront.net/github/images/techdocs.png -[setup-image]: https://d3i6fms1cm1j0i.cloudfront.net/github/images/setup.png -[roadmap-image]: https://d3i6fms1cm1j0i.cloudfront.net/github/images/roadmap.png [contributing-image]: https://d3i6fms1cm1j0i.cloudfront.net/github/images/contributing.png - -[techdocs]: https://github.com/snowplow/snowplow/wiki/Ruby-Tracker -[setup]: https://github.com/snowplow/snowplow/wiki/Ruby-Tracker-Setup -[roadmap]: https://github.com/snowplow/snowplow/wiki/Ruby-Tracker-Roadmap - -[tracker-classificiation]: https://github.com/snowplow/snowplow/wiki/Tracker-Maintenance-Classification +[techdocs]: https://docs.snowplowanalytics.com/docs/collecting-data/collecting-from-own-applications/ruby-tracker/ +[tracker-classification]: https://docs.snowplowanalytics.com/docs/collecting-data/collecting-from-own-applications/tracker-maintenance-classification/ [early-release]: https://img.shields.io/static/v1?style=flat&label=Snowplow&message=Early%20Release&color=014477&labelColor=9ba0aa&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAeFBMVEVMaXGXANeYANeXANZbAJmXANeUANSQAM+XANeMAMpaAJhZAJeZANiXANaXANaOAM2WANVnAKWXANZ9ALtmAKVaAJmXANZaAJlXAJZdAJxaAJlZAJdbAJlbAJmQAM+UANKZANhhAJ+EAL+BAL9oAKZnAKVjAKF1ALNBd8J1AAAAKHRSTlMAa1hWXyteBTQJIEwRgUh2JjJon21wcBgNfmc+JlOBQjwezWF2l5dXzkW3/wAAAHpJREFUeNokhQOCA1EAxTL85hi7dXv/E5YPCYBq5DeN4pcqV1XbtW/xTVMIMAZE0cBHEaZhBmIQwCFofeprPUHqjmD/+7peztd62dWQRkvrQayXkn01f/gWp2CrxfjY7rcZ5V7DEMDQgmEozFpZqLUYDsNwOqbnMLwPAJEwCopZxKttAAAAAElFTkSuQmCC diff --git a/Vagrantfile b/Vagrantfile deleted file mode 100644 index ad8417d..0000000 --- a/Vagrantfile +++ /dev/null @@ -1,23 +0,0 @@ -Vagrant.configure("2") do |config| - - config.vm.box = "ubuntu/trusty64" - config.vm.hostname = "snowplow-ruby-tracker" - config.ssh.forward_agent = true - - config.vm.provider :virtualbox do |vb| - vb.name = Dir.pwd().split("/")[-1] + "-" + Time.now.to_f.to_i.to_s - vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] - vb.customize [ "guestproperty", "set", :id, "--timesync-threshold", 10000 ] - vb.memory = 2048 - end - - config.vm.provision :shell do |sh| - sh.path = "vagrant/up.bash" - end - - # Requires Vagrant 1.7.0+ - config.push.define "gem", strategy: "local-exec" do |push| - push.script = "vagrant/push.bash" - end - -end diff --git a/snowplow-tracker.gemspec b/snowplow-tracker.gemspec index 997361e..f4ff218 100644 --- a/snowplow-tracker.gemspec +++ b/snowplow-tracker.gemspec @@ -15,15 +15,11 @@ # # -*- encoding: utf-8 -*- -lib = File.expand_path('../lib', __FILE__) - -$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'snowplow-tracker/version' +require_relative 'lib/snowplow-tracker/version' Gem::Specification.new do |s| s.name = 'snowplow-tracker' s.version = SnowplowTracker::VERSION - s.date = File.mtime('./lib/snowplow-tracker/version.rb').strftime('%Y-%m-%d') s.homepage = 'http://github.com/snowplow/snowplow-ruby-tracker' s.license = 'Apache License 2.0' s.summary = "Ruby Analytics for Snowplow" diff --git a/vagrant/.gitignore b/vagrant/.gitignore deleted file mode 100644 index 5b164d3..0000000 --- a/vagrant/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -oss-playbooks -ansible -.peru diff --git a/vagrant/ansible.hosts b/vagrant/ansible.hosts deleted file mode 100644 index 588fa08..0000000 --- a/vagrant/ansible.hosts +++ /dev/null @@ -1,2 +0,0 @@ -[vagrant] -127.0.0.1:2222 diff --git a/vagrant/peru.yaml b/vagrant/peru.yaml deleted file mode 100644 index e7fdf41..0000000 --- a/vagrant/peru.yaml +++ /dev/null @@ -1,14 +0,0 @@ -imports: - ansible: ansible - ansible_playbooks: oss-playbooks - -curl module ansible: - # Equivalent of git cloning tags/v1.6.6 but much, much faster - url: https://codeload.github.com/ansible/ansible/zip/69d85c22c7475ccf8169b6ec9dee3ee28c92a314 - unpack: zip - export: ansible-69d85c22c7475ccf8169b6ec9dee3ee28c92a314 - -git module ansible_playbooks: - url: https://github.com/snowplow/ansible-playbooks.git - # Comment out to fetch a specific rev instead of master: - # rev: xxx diff --git a/vagrant/push.bash b/vagrant/push.bash deleted file mode 100755 index 339d72a..0000000 --- a/vagrant/push.bash +++ /dev/null @@ -1,79 +0,0 @@ -#!/bin/bash -set -e - -# Constants -rubygems_user=snowplow -rubygems_gem=snowplow-tracker - -# Check if our Vagrant box is running. Expects `vagrant status` to look like: -# -# > Current machine states: -# > -# > default poweroff (virtualbox) -# > -# > The VM is powered off. To restart the VM, simply run `vagrant up` -function running { - set +e - vagrant status | sed -n 3p | grep -q "^default\s*running (virtualbox)$" - local is_running=$? - set -e - echo $is_running -} - -# Reads the version out of lib/snowplow-tracker/version.rb -function parse_version { - cat lib/snowplow-tracker/version.rb | awk '/ VERSION =/ {v=$3; gsub(/\047/, "", v)} END {print v}' -} - -# Installs RubyGems.org credentials in our guest -# -# Parameters: -# 1. rubygems_password -function install_creds { - vagrant ssh -c "curl -u ${rubygems_user}:${1} https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials" - vagrant ssh -c "chmod 0600 ~/.gem/credentials" -} - -# Builds our gem -function build_gem { - vagrant ssh -c "cd /vagrant && gem build ${rubygems_gem}.gemspec" -} - -# Installs our gem -# -# Parameters: -# 1. rubygems_version -function install_gem { - vagrant ssh -c "cd /vagrant && sudo gem install ./${rubygems_gem}-${1}.gem" -} - -# Pushes our gem to RubyGems.org -# -# Parameters: -# 1. rubygems_version -function push_gem { - vagrant ssh -c "cd /vagrant && gem push ./${rubygems_gem}-${1}.gem" -} - - -# Move to the parent directory of this script -source="${BASH_SOURCE[0]}" -while [ -h "${source}" ] ; do source="$(readlink "${source}")"; done -dir="$( cd -P "$( dirname "${source}" )/.." && pwd )" -cd ${dir} - -# Precondition for running -if [ $(running) != "0" ]; then - echo "Vagrant guest must be running to push" - exit 1 -fi - -# Can't pass args thru vagrant push so have to prompt -read -e -p "Please enter password for RubyGems.org user ${rubygems_user}: " rubygems_password - -# Build, install & push -build_gem -rubygems_version=$(parse_version) -install_gem ${rubygems_version} -install_creds ${rubygems_password} -push_gem ${rubygems_version} diff --git a/vagrant/up.bash b/vagrant/up.bash deleted file mode 100755 index 7450ae8..0000000 --- a/vagrant/up.bash +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/bash -set -e - -vagrant_dir=/vagrant/vagrant -bashrc=/home/vagrant/.bashrc - -echo "========================================" -echo "INSTALLING PERU AND ANSIBLE DEPENDENCIES" -echo "----------------------------------------" -apt-get update -apt-get install -y language-pack-en git unzip libyaml-dev python3-pip python-yaml python-paramiko python-jinja2 - -echo "===============" -echo "INSTALLING PERU" -echo "---------------" -sudo pip3 install peru - -echo "=======================================" -echo "CLONING ANSIBLE AND PLAYBOOKS WITH PERU" -echo "---------------------------------------" -cd ${vagrant_dir} && peru sync -v -echo "... done" - -env_setup=${vagrant_dir}/ansible/hacking/env-setup -hosts=${vagrant_dir}/ansible.hosts - -echo "===================" -echo "CONFIGURING ANSIBLE" -echo "-------------------" -touch ${bashrc} -echo "source ${env_setup}" >> ${bashrc} -echo "export ANSIBLE_HOSTS=${hosts}" >> ${bashrc} -echo "... done" - -echo "==========================================" -echo "RUNNING PLAYBOOKS WITH ANSIBLE*" -echo "* no output while each playbook is running" -echo "------------------------------------------" -while read pb; do - su - -c "source ${env_setup} && ${vagrant_dir}/ansible/bin/ansible-playbook ${vagrant_dir}/${pb} --connection=local --inventory-file=${hosts}" vagrant -done <${vagrant_dir}/up.playbooks - -guidance=${vagrant_dir}/up.guidance - -if [ -f ${guidance} ]; then - echo "===========" - echo "PLEASE READ" - echo "-----------" - cat $guidance -fi diff --git a/vagrant/up.guidance b/vagrant/up.guidance deleted file mode 100644 index e04d958..0000000 --- a/vagrant/up.guidance +++ /dev/null @@ -1,6 +0,0 @@ -To get started: -vagrant ssh -cd /vagrant -gem install bundler -bundle install -rspec diff --git a/vagrant/up.playbooks b/vagrant/up.playbooks deleted file mode 100644 index fa931bd..0000000 --- a/vagrant/up.playbooks +++ /dev/null @@ -1 +0,0 @@ -oss-playbooks/ruby-rvm.yml