Skip to content

Commit

Permalink
Excluded Docker and SLC from DSS Docker Container
Browse files Browse the repository at this point in the history
  • Loading branch information
ckunki committed Nov 3, 2023
1 parent 175a3b9 commit c768db7
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 73 deletions.
88 changes: 37 additions & 51 deletions exasol/ds/sandbox/lib/dss_docker/create_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,57 +30,43 @@


def create_image():
with tempfile.TemporaryDirectory() as tmp_path:
docker_env = docker.from_env()
path = Path(__file__).parent
_logger.info(
f"Creating docker image {CONTAINER_IMAGE_TAG}"
f" from {path / 'Dockerfile'}"
f" in tmp path {tmp_path}"
)
docker_env.images.build(path=str(path), tag=CONTAINER_IMAGE_TAG)
socket_mount = Mount("/var/run/docker.sock", "/var/run/docker.sock", type="bind")
tmp_mount = Mount(tmp_path, tmp_path, type="bind")
container = docker_env.containers.create(
image=CONTAINER_IMAGE_TAG,
name=CONTAINER_NAME,
mounts=[socket_mount, tmp_mount],
command="sleep infinity",
detach=True,
)
_logger.info("Starting container")
container.start()
extra_vars = {
"docker_container": container.name,
# Is it wise / required to use a temp folder here
# and mount it to docker container?
"slc_dest_folder": f"{tmp_path}/script-languages-release",
}
ansible_run_context = AnsibleRunContext(
playbook="slc_docker_playbook.yml", extra_vars=extra_vars)
try:
run_install_dependencies(
AnsibleAccess(),
configuration=ANSIBLE_CONFIG,
host_infos=tuple(),
ansible_run_context=ansible_run_context,
ansible_repositories=ansible_repository.default_repositories,
)
# Note: script-languages-release will be cloned by ansible within the docker container.
# Because the docker container runs as root, the repository will be owned by root.
# For simplicity, we delete the folder from within the Docker container (as root).
# Otherwise, we get a permission problem when tmp_path tries to clean-up itself.
except Exception as ex:
raise ex
finally:
container.commit(
repository=f"exasol/{CONTAINER_IMAGE_TAG}",
tag="latest",
)
_logger.info("Cleaning up")
container.exec_run(f"rm -rf {tmp_path}/script-languages-release")
container.stop()
container.remove()
docker_env = docker.from_env()
path = Path(__file__).parent
_logger.info(
f"Creating docker image {CONTAINER_IMAGE_TAG}"
f" from {path / 'Dockerfile'}"
)
docker_env.images.build(path=str(path), tag=CONTAINER_IMAGE_TAG)
socket_mount = Mount("/var/run/docker.sock", "/var/run/docker.sock", type="bind")
container = docker_env.containers.create(
image=CONTAINER_IMAGE_TAG,
name=CONTAINER_NAME,
command="sleep infinity",
detach=True,
)
_logger.info("Starting container")
container.start()
extra_vars = {
"docker_container": container.name,
}
ansible_run_context = AnsibleRunContext(
playbook="dss_docker_playbook.yml", extra_vars=extra_vars)
run_install_dependencies(
AnsibleAccess(),
configuration=ANSIBLE_CONFIG,
host_infos=tuple(),
ansible_run_context=ansible_run_context,
ansible_repositories=ansible_repository.default_repositories,
)
_logger.info("Committing changes to docker container")
container.commit(
repository=f"exasol/{CONTAINER_IMAGE_TAG}",
tag="latest",
)
_logger.info("Stopping container")
container.stop()
_logger.info("Removing container")
container.remove()


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@
vars:
ansible_python_interpreter: python3
tasks:
- name: add docker container to inventory
add_host:
name: "{{docker_container}}"
ansible_connection: docker
- name: add pexepect
- name: Add docker container to inventory
add_host:
name: "{{docker_container}}"
ansible_connection: docker

- name: Setup Docker Container
- name: Setup DSS Docker Container
hosts: ds-sandbox-docker # cannot use variable here
gather_facts: false
vars:
Expand All @@ -23,4 +19,4 @@
need_sudo: false
docker_integration_test: true
tasks:
- import_tasks: slc_setup_tasks.yml
- import_tasks: general_setup_tasks.yml
8 changes: 7 additions & 1 deletion exasol/ds/sandbox/runtime/ansible/ec2_setup_tasks.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
- name: Install Docker
include_role:
name: docker
- name: Install Script_languages
include_role:
name: script_languages
- name: Update netplan
include_role:
name: netplan
name: netplan
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@
become: "{{need_sudo}}"
- name: Install Poetry
include_role:
name: poetry
name: poetry
- name: Install Jupyter
include_role:
name: jupyter
- name: Install Docker
include_role:
name: docker
- name: Install Script_languages
include_role:
name: script_languages
name: jupyter
- name: Clear pip cache
ansible.builtin.file:
path: /root/.cache/pip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

- name: Setup Jupyter
block:
- name: Install dependant apt packages
- name: Install dependent apt packages
apt:
name: "{{apt_dependencies}}"
state: present
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---

- name: Install dependant apt packages
- name: Install dependent apt packages
apt:
name: "{{apt_dependencies}}"
state: present
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---

- name: Install dependant apt packages
- name: Install dependent apt packages
apt:
name: "{{apt_dependencies}}"
state: present
Expand Down
2 changes: 1 addition & 1 deletion exasol/ds/sandbox/runtime/ansible/slc_setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
need_sudo: yes
remote_user: ubuntu
tasks:
- import_tasks: slc_setup_tasks.yml
- import_tasks: general_setup_tasks.yml
- import_tasks: ec2_setup_tasks.yml
2 changes: 1 addition & 1 deletion test/ansible/slc_setup_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
name: netplan.io
state: present
update_cache: yes
- import_tasks: slc_setup_tasks.yml
- import_tasks: general_setup_tasks.yml
- import_tasks: ec2_setup_tasks.yml
2 changes: 1 addition & 1 deletion test/unit/ansible_conflict/slc_setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
name: netplan.io
state: present
update_cache: yes
- import_tasks: slc_setup_tasks.yml
- import_tasks: general_setup_tasks.yml
- import_tasks: ec2_setup_tasks.yml

0 comments on commit c768db7

Please sign in to comment.