-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#110: Allow to "start", "stop" and "rm" the container for local proje…
…ct and "cikit ssh" inside of it
- Loading branch information
Showing
15 changed files
with
191 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
!lib/ | ||
!cmf/ | ||
!docs/ | ||
!env/ | ||
docs/_site/ | ||
!tests/ | ||
!scripts/ | ||
|
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,3 @@ | ||
# requires-project-root | ||
--- | ||
- import_playbook: start.yml __action=rm |
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,28 @@ | ||
# requires-project-root | ||
--- | ||
- hosts: localhost | ||
connection: local | ||
gather_facts: no | ||
|
||
vars_files: | ||
- "{{ __targetdir__ }}/.cikit/config.yml" | ||
|
||
vars: | ||
__action: start | ||
|
||
tasks: | ||
- name: Define the hostname | ||
set_fact: | ||
hostname: "{{ site_url.split('//') | last }}" | ||
mounts: "" | ||
ports: "" | ||
|
||
- name: Check whether container exists | ||
shell: "docker ps -qaf name='^/{{ hostname }}'" | ||
register: container_exists | ||
|
||
- include_tasks: tasks/create.yml | ||
when: "not container_exists.stdout and 'start' == __action" | ||
|
||
- include_tasks: "tasks/{{ __action }}.yml" | ||
when: container_exists.stdout |
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,3 @@ | ||
# requires-project-root | ||
--- | ||
- import_playbook: start.yml __action=stop |
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,35 @@ | ||
--- | ||
- name: Define the mounts | ||
set_fact: | ||
mounts: |- | ||
{{ mounts }} -v '{{ item.source if item.source[0] == '/' else __targetdir__ + '/' + item.source }}':'{{ item['target' if item.target else 'source'] }}' | ||
with_items: "{{ vm.folders }}" | ||
|
||
- name: Define the ports | ||
set_fact: | ||
ports: |- | ||
{{ ports }} -p {{ item }} | ||
with_items: "{{ vm.ports }}" | ||
|
||
- name: Create the container | ||
# @todo These options aren't working on macOS. | ||
# -v /sys/fs/cgroup:/sys/fs/cgroup:ro \ | ||
# --tmpfs /run \ | ||
# --tmpfs /run/lock \ | ||
# --security-opt seccomp=unconfined \ | ||
shell: |- | ||
docker run \ | ||
-d \ | ||
-h '{{ hostname }}' \ | ||
--name '{{ hostname }}' \ | ||
{{ mounts }} \ | ||
{{ ports }} \ | ||
solita/ubuntu-systemd | ||
- name: Install the requirements | ||
shell: |- | ||
docker exec -t {{ hostname }} bash -c 'apt update -y && apt install sudo dbus python-minimal -y && service dbus restart' | ||
- name: Print the name of created container | ||
debug: | ||
msg: "The '{{ hostname }}' just have been created." |
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,3 @@ | ||
--- | ||
- name: "{{ operation | default(command | capitalize) }} the '{{ hostname }}' container" | ||
shell: docker {{ command }} {{ hostname }} |
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,4 @@ | ||
--- | ||
- name: Check whether container is running | ||
shell: "docker inspect -f {% raw %}{{.State.Running}}{% endraw %} {{ hostname }}" | ||
register: container_running |
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,7 @@ | ||
--- | ||
- include_tasks: stop.yml | ||
|
||
- include_tasks: do.yml | ||
args: | ||
command: rm | ||
operation: Remove |
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,5 @@ | ||
--- | ||
- include_tasks: is-running.yml | ||
|
||
- include_tasks: do.yml command=start | ||
when: not container_running.stdout | bool |
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,5 @@ | ||
--- | ||
- include_tasks: is-running.yml | ||
|
||
- include_tasks: do.yml command=stop | ||
when: container_running.stdout | bool |
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
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