From 497edc66add692f742f490244e0f286b57d127e8 Mon Sep 17 00:00:00 2001 From: Kris Lamoureux Date: Tue, 17 Sep 2019 22:32:08 -0400 Subject: [PATCH] Create basic Docker environment Creates a Debian 10 environment with Docker and Docker Compose --- .gitignore | 1 + Vagrantfile | 23 +++++++++++++++ moxie.yml | 35 ++++++++++++++++++++++ roles/docker/docker-ce.list | 1 + roles/docker/install-compose.sh | 38 ++++++++++++++++++++++++ roles/docker/tasks/main.yml | 52 +++++++++++++++++++++++++++++++++ 6 files changed, 150 insertions(+) create mode 100644 .gitignore create mode 100644 Vagrantfile create mode 100644 moxie.yml create mode 100644 roles/docker/docker-ce.list create mode 100644 roles/docker/install-compose.sh create mode 100644 roles/docker/tasks/main.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8000dd9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vagrant diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..f2e98a9 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,23 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.configure("2") do |config| + config.vm.box = "debian/buster64" + config.vm.synced_folder ".", "/vagrant", disabled: true + + # Machine Name + config.vm.define :moxie do |moxie| # + end + + # Disable Machine Name Prefix + config.vm.provider :libvirt do |libvirt| + libvirt.default_prefix = "" + end + + # Provision with Ansible + config.vm.provision "ansible" do |ansible| + ansible.compatibility_mode = "2.0" + ansible.playbook = "moxie.yml" + end + +end diff --git a/moxie.yml b/moxie.yml new file mode 100644 index 0000000..583deac --- /dev/null +++ b/moxie.yml @@ -0,0 +1,35 @@ +# Copyright (C) 2019 Kris Lamoureux +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +- name: Install Moxie Server + hosts: all + become: true + + # Install host requirements for playbooks + pre_tasks: + + - name: 'Install Ansible dependency: python-apt' + shell: 'apt-get update && apt-get install python-apt -y' + args: + creates: /usr/lib/python2.7/dist-packages/apt + warn: false + + - name: 'Install Ansible dependency: aptitude' + apt: + name: 'aptitude' + state: present + force_apt_get: true + + roles: + - docker diff --git a/roles/docker/docker-ce.list b/roles/docker/docker-ce.list new file mode 100644 index 0000000..d7d2f36 --- /dev/null +++ b/roles/docker/docker-ce.list @@ -0,0 +1 @@ +deb [arch=amd64] https://download.docker.com/linux/debian buster stable diff --git a/roles/docker/install-compose.sh b/roles/docker/install-compose.sh new file mode 100644 index 0000000..29dea61 --- /dev/null +++ b/roles/docker/install-compose.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# Github username and repo name +user="docker" +repo="compose" + +# Retrieve the latest version number +addr="https://github.com/$user/$repo/releases/latest" +page=$(curl -s $addr | grep -o releases/tag/*.*\") +version=$(echo $page | awk '{print substr($1, 14, length($1) - 14)}') + +# Download prep +url="https://github.com/$user/$repo/releases/download/$version" +file="docker-compose-$(uname -s)-$(uname -m)" + +# Download latest Docker Compose if that version hasn't been downloaded +if [ ! -f /tmp/docker_compose_$version ]; then + curl -L $url/$file -o /tmp/docker-compose_$version +fi + +# Is it already installed? +if installed=$(which docker-compose); then + + new_chksum=$(sha256sum /tmp/docker-compose_$version) + old_chksum=$(sha256sum /usr/local/bin/docker-compose) + + # If checksums are different, delete and install new version + if [ ! "$new_chksum" = "$old_chksum" ]; then + rm /usr/local/bin/docker-compose + mv /tmp/docker-compose_$version /usr/local/bin/docker-compose + chmod +x /usr/local/bin/docker-compose + fi + +else + # It's not installed, so no need to remove + mv /tmp/docker-compose_$version /usr/local/bin/docker-compose + chmod +x /usr/local/bin/docker-compose +fi diff --git a/roles/docker/tasks/main.yml b/roles/docker/tasks/main.yml new file mode 100644 index 0000000..0e14e00 --- /dev/null +++ b/roles/docker/tasks/main.yml @@ -0,0 +1,52 @@ +# Copyright (C) 2019 Kris Lamoureux +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +- name: Remove old versions of Docker + apt: + name: ['docker', 'docker-engine', 'docker.io', 'containerd', 'runc'] + state: absent + update_cache: true + +- name: Install HTTPS capability for apt + apt: + name: ['apt-transport-https', 'ca-certificates', + 'curl', 'gnupg2', 'software-properties-common'] + state: present + +- name: Install Docker's signing key + apt_key: + url: https://download.docker.com/linux/debian/gpg + id: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88 + state: present + +- name: Install Docker's stable repository + template: + src: docker-ce.list + dest: /etc/apt/sources.list.d/docker-ce.list + +- name: Install Docker CE + apt: + name: ['docker-ce', 'docker-ce-cli', 'containerd.io'] + state: present + update_cache: true + +- name: Add user to docker group + user: + name: vagrant + groups: docker + +- name: Install docker-compose + script: install-compose.sh + args: + creates: /usr/local/bin/docker-compose