Skip to content

Commit

Permalink
- Mounting sources to a docker container instead copying them into a …
Browse files Browse the repository at this point in the history
…docker image
  • Loading branch information
soksanichenko committed Feb 6, 2024
1 parent 531122f commit 5a77a2b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
3 changes: 3 additions & 0 deletions deploy/roles/deploy_bot_container/defaults/main/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
docker_lib_folder: "/var/lib/docker"
...
31 changes: 29 additions & 2 deletions deploy/roles/deploy_bot_container/tasks/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,27 @@
dest: "/tmp/Dockerfile"
src: "Dockerfile.j2"

- name: Create volume directory for a container
file:
path: "{{ docker_lib_folder }}/volumes/meow-bot/sources"
recurse: yes
state: directory
owner: root
group: root
become: yes

- name: Copy req.txt for building a docker image
copy:
dest: "/tmp/req.txt"
src: "../../../../sources/req.txt"

- name: Copy sources
synchronize:
dest: "/tmp/sources"
src: "../../../../sources"
dest: "{{ docker_lib_folder }}/volumes/meow-bot/sources"
src: "../../../../sources/"
owner: false
group: false
become: yes

- name: Build a docker image
docker_image:
Expand All @@ -27,5 +44,15 @@
state: started
restart_policy: always
restart: yes
mounts:
- source: "{{ docker_lib_folder }}/volumes/meow-bot/sources"
target: "/code/sources"
read_only: yes
type: bind
become: yes

- name: Remove Dockerfile
file:
path: "/tmp/Dockerfile"
state: absent
...
8 changes: 4 additions & 4 deletions deploy/roles/deploy_bot_container/templates/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM almalinux:9
RUN dnf install python39 -y
RUN mkdir -p /code
RUN mkdir -p /code/sources
WORKDIR /code
COPY req.txt sources/req.txt
RUN python3.9 -m venv --system-site-packages --symlinks venv
COPY /sources/* .
RUN source venv/bin/activate && pip install -r req.txt
RUN source venv/bin/activate && pip install -r sources/req.txt
ENV DISCORD_TOKEN="{{ discord_token }}"
ENTRYPOINT ["venv/bin/python3", "main.py"]
ENTRYPOINT ["venv/bin/python3", "sources/main.py"]

0 comments on commit 5a77a2b

Please sign in to comment.