Skip to content

Commit c3df027

Browse files
committed
feat: Configure Docker and Devcontainer for development environment
This commit enhances the development environment by configuring Docker and the Devcontainer for improved development workflows. - Updates the .devcontainer/Dockerfile to install Docker CE, configure the Docker socket, and clean up unnecessary files. - Modifies the backend/Dockerfile to create a /logs directory and adjust permissions. - Updates the .devcontainer/devcontainer.json to mount the Docker socket and set the PYTHONPATH. - Updates the .devcontainer/docker-compose.yml to mount the logs directory and add an extra host for Docker. - Adds imports to backend/core/tests/test_processes.py
1 parent f13d2b2 commit c3df027

5 files changed

Lines changed: 32 additions & 3 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,25 @@ ENV PYTHONDONTWRITEBYTECODE=1
88
# This option has no effect on the stdin stream.
99
ENV PYTHONUNBUFFERED=1
1010

11+
RUN apt-get update \
12+
&& apt-get -y install --no-install-recommends \
13+
apt-transport-https \
14+
ca-certificates \
15+
curl \
16+
gnupg2 \
17+
software-properties-common \
18+
&& curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add - \
19+
&& add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" \
20+
&& apt-get update \
21+
&& apt-get -y install --no-install-recommends docker-ce \
22+
# Clean up
23+
&& apt-get autoremove -y \
24+
&& apt-get clean -y \
25+
&& rm -rf /var/lib/apt/lists/*
26+
27+
# Symlink docker socket
28+
RUN ln -s "/var/run/docker-host.sock" "/var/run/docker.sock"
29+
1130
# [Optional] If your requirements rarely change, uncomment this section to add them to the image.
1231
COPY ./backend/requirements.txt /tmp/pip-tmp/
1332
RUN pip install --upgrade pip wheel setuptools \

.devcontainer/devcontainer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@
5050
]
5151
}
5252
},
53+
"mounts": [
54+
"source=/var/run/docker.sock,target=/var/run/docker-host.sock,type=bind"
55+
],
5356
"containerEnv": {
54-
//"PYTHONPATH": "/workspaces/process_api/backend:$PYTHONPATH"
5557
"PYTHONPATH": "/workspaces/${localWorkspaceFolderBasename}:$PYTHONPATH"
5658
}
5759
// Features to add to the dev container. More info: https://containers.dev/features.

.devcontainer/docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ services:
1111
- ./datasets:/datasets # datasets repo
1212
- ./processes:/processes
1313
- ./logs:/logs
14+
extra_hosts:
15+
- "host.docker.internal:host-gateway"
1416

1517
# Overrides default command so things don't shut down after the process ends.
1618
command: sleep infinity

backend/Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ ARG GROUPID=1000
7070
ARG BASEDIR=/app
7171

7272
ENV BASE_DIR ${BASEDIR}
73+
ENV LOG_DIR ${LOG_DIR}
7374

74-
RUN mkdir -p ${BASE_DIR}
75+
RUN mkdir -p ${BASE_DIR} /logs
7576

7677
# Copy app files into container
7778
WORKDIR $BASE_DIR
@@ -81,7 +82,8 @@ RUN mkdir -p ${BASE_DIR}/django_static \
8182
${BASE_DIR}/django_static/rest_framework \
8283
${BASE_DIR}/django_static/admin \
8384
${BASE_DIR}/core/migrations \
84-
&& chmod -R g+w ${BASE_DIR}
85+
&& chmod -R g+w ${BASE_DIR} \
86+
&& chmod -R g+w /logs
8587

8688
# Create group
8789
RUN groupadd --gid ${GROUPID} $USERNAME

backend/core/tests/test_processes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
import logging
2+
import pytest
3+
from django.conf import settings
14
from rest_framework.test import APITestCase
25

36

7+
48
class ProcessesAPIViewTestCase(APITestCase):
59

610
def test_list_product(self):

0 commit comments

Comments
 (0)