-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from naftulikay/feature/fix-docker-compose
Docker Compose Support
- Loading branch information
Showing
10 changed files
with
139 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,20 @@ | ||
#!/usr/bin/make -f | ||
ROLE_NAME:=vagrant-docker | ||
MOUNT_PATH:=/etc/ansible/roles/$(ROLE_NAME) | ||
|
||
# TODO trusty needs not systemd flags | ||
SYSTEMD_FLAGS:=--privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro | ||
DEFAULT_IMAGE:=loki | ||
IMAGE:=$(shell echo "$${IMAGE:-$(DEFAULT_IMAGE)}") | ||
|
||
LOCAL_FLAGS:=-v $(shell pwd):$(MOUNT_PATH):ro -v $(shell pwd)/ansible.cfg:/etc/ansible/ansible.cfg:ro | ||
SELINUX_FLAGS:= | ||
clean: | ||
@docker-compose rm -fs $(IMAGE) | ||
|
||
CONTAINER_ID_DIR:=/tmp/container/$(IMAGE_NAME) | ||
CONTAINER_ID_FILE:=$(CONTAINER_ID_DIR)/id | ||
CONTAINER_ID:=$(shell cat "$(CONTAINER_ID_FILE)" 2>/dev/null) | ||
start: | ||
@docker-compose up -d $(IMAGE) | ||
|
||
validate: | ||
ifeq ($(IMAGE_NAME),) | ||
@echo "IMAGE_NAME is undefined, please define it." | ||
@exit 1 | ||
endif | ||
ifeq ($(ROLE_NAME),) | ||
@echo "ROLE_NAME is undefined, please define it." | ||
@exit 1 | ||
endif | ||
shell: start | ||
@docker exec -it $(IMAGE) bash | ||
|
||
# get status of the vm-like container | ||
status: validate | ||
@if [ -z "$(CONTAINER_ID)" ]; then \ | ||
echo "Container Not Running" ; \ | ||
exit 1 ; \ | ||
else \ | ||
echo "Container Running" ; \ | ||
fi | ||
|
||
start: validate | ||
@if [ ! -z "$(CONTAINER_ID)" ]; then \ | ||
echo "ERROR: Container Already Running: $(CONTAINER_ID)" >&2 ; \ | ||
exit 1 ; \ | ||
fi | ||
@# start it | ||
@echo "Starting the Container:" | ||
@test -d "$(CONTAINER_ID_DIR)" || mkdir -p "$(CONTAINER_ID_DIR)" | ||
docker pull $(IMAGE_NAME) | ||
docker pull docker:stable-dind | ||
docker run -d --privileged --name dind docker:stable-dind | ||
docker run -d --link dind:docker $(SYSTEMD_FLAGS) $(LOCAL_FLAGS) $$(test -d /etc/selinux && echo $(SELINUX_FLAGS)) $(IMAGE_NAME) > $(CONTAINER_ID_FILE) | ||
|
||
stop: validate | ||
@if [ -z "$(CONTAINER_ID)" ] && ! docker ps --filter id=$(CONTAINER_ID) --format '{{.ID}}' | grep -qP '.*' ; then \ | ||
echo "ERROR: Container Not Running" >&2 ; \ | ||
rm -f $(CONTAINER_ID_FILE) ; \ | ||
exit 0 ; \ | ||
fi ; \ | ||
docker kill $(CONTAINER_ID) > /dev/null ; \ | ||
docker rm -f -v $(CONTAINER_ID) > /dev/null ; \ | ||
docker rm -f -v dind ; \ | ||
rm -f $(CONTAINER_ID_FILE) ; \ | ||
echo "Stopped Container $(CONTAINER_ID)" | ||
|
||
restart: | ||
$(MAKE) stop | ||
$(MAKE) start | ||
|
||
shell: status | ||
docker exec -it $(CONTAINER_ID) /bin/bash - | ||
|
||
test: | ||
@if [ -z "$(CONTAINER_ID)" ]; then \ | ||
echo "ERROR: Container Not Running" >&2 ; \ | ||
exit 1 ; \ | ||
fi | ||
@# need a way to ask systemd in the container to wait until all services up | ||
docker exec $(CONTAINER_ID) ansible --version | ||
docker exec $(CONTAINER_ID) wait-for-boot | ||
docker exec $(CONTAINER_ID) ansible-galaxy install -r ${MOUNT_PATH}/tests/requirements.yml | ||
docker exec $(CONTAINER_ID) env ANSIBLE_FORCE_COLOR=yes \ | ||
ansible-playbook $(MOUNT_PATH)/tests/playbook.yml | ||
|
||
test-clean: | ||
$(MAKE) restart | ||
$(MAKE) test | ||
test: 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
--- | ||
vagrant_user: vagrant | ||
docker_users: ["{{ vagrant_user }}"] | ||
|
||
docker_compose_matcher: ^https://github.com/docker/compose/releases/tag/(?P<release>\d+\.\d+\.\d+)$ | ||
docker_compose_replace: \g<release> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
--- | ||
version: '3' | ||
services: | ||
|
||
dind: | ||
container_name: dind | ||
image: docker:stable-dind | ||
privileged: true | ||
|
||
centos7: | ||
container_name: centos7 | ||
image: naftulikay/centos-vm:latest | ||
privileged: true | ||
depends_on: | ||
- dind | ||
links: | ||
- dind:docker | ||
volumes: | ||
- /sys/fs/cgroup:/sys/fs/cgroup:ro | ||
- ./:/etc/ansible/roles/default:ro | ||
- ./ansible.cfg:/etc/ansible/ansible.cfg:ro | ||
stop_grace_period: 1s | ||
|
||
loki: | ||
container_name: loki | ||
image: naftulikay/loki-vm:latest | ||
privileged: true | ||
depends_on: | ||
- dind | ||
links: | ||
- dind:docker | ||
volumes: | ||
- /sys/fs/cgroup:/sys/fs/cgroup:ro | ||
- ./:/etc/ansible/roles/default:ro | ||
- ./ansible.cfg:/etc/ansible/ansible.cfg:ro | ||
stop_grace_period: 1s | ||
|
||
trusty: | ||
container_name: trusty | ||
image: naftulikay/trusty-vm:latest | ||
depends_on: | ||
- dind | ||
links: | ||
- dind:docker | ||
volumes: | ||
- /sys/fs/cgroup:/sys/fs/cgroup:ro | ||
- ./:/etc/ansible/roles/default:ro | ||
- ./ansible.cfg:/etc/ansible/ansible.cfg:ro | ||
stop_grace_period: 1s | ||
|
||
xenial: | ||
container_name: xenial | ||
image: naftulikay/xenial-vm:latest | ||
privileged: true | ||
depends_on: | ||
- dind | ||
links: | ||
- dind:docker | ||
volumes: | ||
- /sys/fs/cgroup:/sys/fs/cgroup:ro | ||
- ./:/etc/ansible/roles/default:ro | ||
- ./ansible.cfg:/etc/ansible/ansible.cfg:ro | ||
stop_grace_period: 1s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,49 @@ | ||
--- | ||
- name: detect latest version | ||
uri: | ||
url: https://github.com/docker/compose/releases/latest | ||
status_code: 302 | ||
follow_redirects: false | ||
register: detected_latest_url | ||
changed_when: false | ||
|
||
- name: establish version | ||
set_fact: | ||
docker_compose_version: "{{ detected_latest_url.location | regex_replace(docker_compose_matcher, docker_compose_replace) }}" | ||
|
||
- name: establish download facts | ||
set_fact: | ||
docker_compose_completion_url: "https://raw.githubusercontent.com/docker/compose/1.21.0/contrib/completion/bash/docker-compose" | ||
docker_compose_download_path: /usr/local/share/docker-compose/{{ docker_compose_version }}/docker-compose | ||
docker_compose_download_url: "https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-{{ ansible_system | lower }}-{{ ansible_architecture }}" | ||
|
||
- name: create install directory | ||
file: path=/usr/local/share/docker-compose/{{ docker_compose_version }} state=directory owner=root group=root | ||
become: true | ||
|
||
- name: install docker compose | ||
package: name=docker-compose state=present | ||
when: ansible_distribution_release != "trusty" | ||
get_url: | ||
url: "{{ docker_compose_download_url }}" | ||
dest: "{{ docker_compose_download_path }}" | ||
owner: root | ||
group: root | ||
mode: 0755 | ||
become: true | ||
|
||
- name: install docker compose completions | ||
get_url: | ||
url: "{{ docker_compose_completion_url }}" | ||
dest: "/etc/bash_completion.d/docker-compose.sh" | ||
mode: 0644 | ||
owner: root | ||
group: root | ||
become: true | ||
|
||
- name: symlink docker compose | ||
file: | ||
src: "{{ docker_compose_download_path }}" | ||
dest: /usr/local/bin/docker-compose | ||
state: link | ||
owner: root | ||
group: root | ||
become: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,6 @@ | ||
--- | ||
user: | ||
# defaults | ||
# vagrant: | ||
# exists: true | ||
# groups: | ||
# contain-element: docker | ||
|
||
# custom run | ||
vagrant2: | ||
vagrant: | ||
exists: true | ||
groups: | ||
contain-element: docker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,4 @@ | |
become: true | ||
roles: | ||
- role: vagrant-base | ||
- role: docker | ||
docker_users: vagrant | ||
- role: vagrant-docker |