Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] OSX Support #20

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
30 changes: 20 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
---
dist: trusty
sudo: required
language: generic

matrix:
fast_finish: true
include:
- os: linux
env: IMAGE=centos7
dist: trusty
services:
- docker
- os: linux
env: IMAGE=loki
dist: trusty
services:
- docker
- os: linux
env: IMAGE=xenial
dist: trusty
services:
- docker
- os: osx
sudo: required

services:
- docker

env:
matrix: # each entry is its own run
- IMAGE: centos7
- IMAGE: xenial

install: make install
script: make clean test

notifications:
Expand Down
61 changes: 48 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,31 +1,66 @@
#!/usr/bin/make -f

ROLE_NAME:=go-dev

.DEFAULT_GOAL := apply
.PHONY: apply

DEFAULT_IMAGE:=centos7
IMAGE:=$(shell echo "$${IMAGE:-$(DEFAULT_IMAGE)}")

clean:
OS:=$(shell uname | tr '[:upper:]' '[:lower:]')

# LINUX ONLY ------------------------------------------------------------------
ifeq ($(OS),linux)
clean-linux:
@docker-compose rm -fs $(IMAGE)

start:
start-linux:
@docker-compose up -d $(IMAGE)

shell: start
@docker exec -it $(IMAGE) bash

test: start
test-linux: start
@docker exec $(IMAGE) ansible --version
@docker exec $(IMAGE) wait-for-boot
@docker exec $(IMAGE) ansible-galaxy install -r /etc/ansible/roles/default/tests/requirements.yml
@docker exec $(IMAGE) env ANSIBLE_FORCE_COLOR=yes \
ansible-playbook /etc/ansible/roles/default/tests/playbook.yml

apply:
@mkdir -p target/ .ansible/galaxy-roles
@rsync --delete --exclude=.ansible/galaxy-roles -a ./ .ansible/galaxy-roles/$(ROLE_NAME)/
@ansible-galaxy install -p .ansible/galaxy-roles -r requirements.yml
@ansible-playbook -i localhost, --ask-become-pass local.yml
install-linux:
@true

install: install-linux
clean: clean-linux
start: start-linux
test: test-linux

shell: start
@docker exec -it $(IMAGE) bash
endif

# OSX ONLY --------------------------------------------------------------------
ifeq ($(OS),darwin)
clean-osx:
@true

start-osx:
@true

test-osx: start
@mkdir -p .ansible/galaxy-roles
@rsync --delete --exclude=.ansible/galaxy-roles -a ./ .ansible/galaxy-roles/default/
@ansible-galaxy install -p .ansible/galaxy-roles -r tests/requirements.yml
@ansible-playbook -c local -i 127.0.0.1, -e test_user=$(shell whoami) --ask-become-pass tests/playbook.yml

install-osx:
@brew install python@2 >/dev/null
@brew link --overwrite python >/dev/null
@brew install ansible >/dev/null
@echo "Dumping Debug Information..."
@echo "Python Version: $$(python --version)"
@echo "pip Version: $$(pip --version)"
@echo "Ansible Version: $$(ansible --version)"

install: install-osx

clean: clean-osx
start: start-osx
test: test-osx
endif
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Available on Ansible Galaxy at [`naftulikay.go-dev`][galaxy].

## Requirements

Currently only Linux and the amd64 architecture are supported, contributions welcome.
Supporting (under test) Ubuntu 16.04, elementary OS Loki, CentOS, and OSX. Only amd64 architecture is supported
for now. Other Unix-like environments may work but are not under test.

## Role Variables

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ services:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- ./:/etc/ansible/roles/default:ro
- ./tests/ansible.cfg:/etc/ansible/ansible.cfg:ro
stop_grace_period: 1s
stop_grace_period: 1s
1 change: 1 addition & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ galaxy_info:
versions:
- trusty
- xenial
- name: MacOSX

galaxy_tags:
- go
Expand Down
10 changes: 0 additions & 10 deletions tasks/discover/go.yml

This file was deleted.

17 changes: 0 additions & 17 deletions tasks/discover/os.yml

This file was deleted.

15 changes: 11 additions & 4 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
fail: msg="go_user must be set."
when: go_user is not defined

- name: discover os facts
include_tasks: discover/os.yml
- name: get go user details
command: sh -c 'echo $HOME'
become: true
become_user: "{{ go_user }}"
become_flags: -Hi
changed_when: false
register: go_user_check
vars:
ansible_ssh_pipelining: "{{ is_macos }}"

- name: discover go facts
include_tasks: discover/go.yml
- name: set go user home
set_fact: go_user_home="{{ go_user_check.stdout_lines[0] }}"

- name: include system tasks
include_tasks: system.yml
Expand Down
39 changes: 36 additions & 3 deletions tasks/system.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,34 @@
- name: update apt cache
apt: update_cache=true cache_valid_time=3600
become: true
when: os_name == "ubuntu"
when: is_ubuntu_derivative

- name: fix homebrew ownership
command: find /usr/local -mindepth 1 -maxdepth 1 -type d -exec chown -R {{ go_user }}:admin {} \;
become: true
when: is_macos

- name: install git
package: name=git state=present
become: true
become_user: |-
{%- if is_linux -%}
root
{%- else -%}
{{ go_user }}
{%- endif -%}
become_flags: -Hi
vars:
ansible_ssh_pipelining: "{{ is_macos }}"

- name: install GNU tar
package: name=gnu-tar state=present
become: true
become_user: "{{ go_user }}"
become_flags: -Hi
when: is_macos
vars:
ansible_ssh_pipelining: "{{ is_macos }}"

- name: download
unarchive:
Expand All @@ -28,14 +51,24 @@
dest: "{{ go_goroot_dir }}"
mode: "0755"
owner: root
group: root
group: |-
{%- if is_macos -%}
admin
{%- else -%}
root
{%- endif -%}
become: true

- name: configure environment
template:
src: go-profile.d.sh.j2
dest: /etc/profile.d/go.sh
owner: root
group: root
group: |-
{%- if is_macos -%}
admin
{%- else -%}
root
{%- endif -%}
mode: 0755
become: true
14 changes: 12 additions & 2 deletions tasks/user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
state: directory
mode: 0700
owner: "{{ go_user }}"
group: "{{ go_user }}"
group: |-
{%- if is_macos -%}
primarygroup
{%- else -%}
{{ go_user }}
{%- endif -%}
recurse: true

- name: detect dep current version
Expand Down Expand Up @@ -53,7 +58,12 @@
url: https://github.com/golang/dep/releases/download/v{{ godep_target_version }}/dep-linux-amd64
dest: "{{ go_user_path.replace('$HOME', go_user_home) }}/bin/dep"
owner: "{{ go_user }}"
group: "{{ go_user }}"
group: |-
{%- if is_macos -%}
primarygroup
{%- else -%}
{{ go_user }}
{%- endif -%}
mode: 0755
force: true
become: true
Expand Down
3 changes: 3 additions & 0 deletions tests/goss.d/commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ command:
exit-status: 0
stdout:
- "{{.Env.go_version}}"

'which fuckyou':
exit-status: 0
2 changes: 1 addition & 1 deletion tests/goss.d/files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ file:
owner: root
group: root
filetype: symlink
linked-to: /usr/local/go-1.8.3
linked-to: /usr/local/go-{{.Env.go_version}}
13 changes: 6 additions & 7 deletions tests/playbook.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
---
- name: setup
hosts: localhost
vars:
container_user: vagrant
become: true
tasks:
- name: create user
user: name={{ container_user }} comment="Container User" shell=/bin/bash state=present
user: name={{ test_user | default('vagrant') }} comment="Container User" shell=/bin/bash state=present

- name: build
hosts: localhost
roles:
- role: default
go_version: 1.8.3
go_user: vagrant
go_version: 1.10.3
go_user: "{{ test_user | default('vagrant') }}"

- name: test
hosts: localhost
Expand All @@ -24,6 +23,6 @@
goss_file: goss.yml
goss_addtl_dirs: [goss.d]
goss_env_vars:
go_version: 1.8.3
go_user: vagrant
go_version: 1.10.3
go_user: "{{ test_user | default('vagrant') }}"
go_goroot_dir: /usr/local/go