Skip to content

Commit

Permalink
update docker and docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
ReiHashimoto committed Jun 28, 2023
1 parent 279d77c commit cb4e068
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 81 deletions.
22 changes: 9 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
FROM --platform=linux/amd64 python:3.8.16-slim

COPY pyproject.toml /app/pyproject.toml

RUN apt-get --allow-releaseinfo-change update && \
apt-get install --no-install-recommends -y gcc g++ libgl1 libgl1-mesa-dev && \
pip3 install --no-cache-dir --upgrade pip && \
pip3 install --no-cache-dir -e 'app/.[test]' && \
apt-get clean && rm -rf /root/.cache/pip/*
WORKDIR /app

RUN mkdir -p /root/miniconda3 && \
apt-get --allow-releaseinfo-change update && \
apt-get install --no-install-recommends -y gcc g++ libgl1 libgl1-mesa-dev && \
apt-get install --no-install-recommends -y wget && \
wget -q https://repo.anaconda.com/miniconda/Miniconda3-py39_4.12.0-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh && \
apt-get purge wget -y && apt-get autoremove -y && apt-get clean && \
Expand All @@ -19,13 +15,13 @@ RUN mkdir -p /root/miniconda3 && \
conda config --set channel_priority strict && \
conda clean -y --tarballs

ENV PATH $PATH:/root/miniconda3/bin

COPY frontend/build /app/frontend/build
COPY studio /app/studio
COPY main.py /app/main.py
COPY main.py pyproject.toml ./

ENV PATH $PATH:/root/miniconda3/bin
WORKDIR /app
EXPOSE 8000
RUN pip3 install --no-cache-dir --upgrade pip && \
pip3 install --no-cache-dir -e .

ENTRYPOINT ["python3", "main.py"]
CMD ["--host", "0.0.0.0"]
EXPOSE 8000
24 changes: 24 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM --platform=linux/amd64 python:3.8.16-slim

WORKDIR /app

RUN mkdir -p /root/miniconda3 && \
apt-get --allow-releaseinfo-change update && \
apt-get install --no-install-recommends -y wget && \
wget -q https://repo.anaconda.com/miniconda/Miniconda3-py39_4.12.0-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh && \
apt-get purge wget -y && apt-get autoremove -y && apt-get clean && \
bash /root/miniconda3/miniconda.sh -b -u -p /root/miniconda3 && \
rm /root/miniconda3/miniconda.sh && \
export PATH="$PATH:/root/miniconda3/bin" && \
conda upgrade -y --all && \
conda config --set channel_priority strict && \
conda clean -y --tarballs

ENV PATH $PATH:/root/miniconda3/bin

COPY pyproject.toml .

RUN pip3 install --no-cache-dir --upgrade pip && \
pip3 install --no-cache-dir -e '.[dev]'

EXPOSE 8000
13 changes: 7 additions & 6 deletions Dockerfile-test → Dockerfile.test
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
FROM --platform=linux/amd64 python:3.8.16-slim

COPY pyproject.toml /app/pyproject.toml
WORKDIR /app

RUN apt-get --allow-releaseinfo-change update && \
apt-get install --no-install-recommends -y git gcc g++ libgl1 && \
pip3 install --no-cache-dir --upgrade pip && \
pip3 install --no-cache-dir -e 'app/.[test]' && \
apt-get purge git -y && apt-get autoremove -y && apt-get clean && rm -rf /root/.cache/pip/*
apt-get purge git -y && apt-get autoremove -y && apt-get clean

WORKDIR /app
ENTRYPOINT ["python3", "-m", "pytest", "-s", "."]
COPY pyproject.toml .
RUN pip3 install --no-cache-dir --upgrade pip && \
pip3 install --no-cache-dir -e '.[test]'

ENTRYPOINT ["python3", "-m", "pytest", "-s", "."]
36 changes: 18 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
.PHONY: test_run
test_run:
docker-compose -f docker-compose.yml down --rmi all --volumes --remove-orphans
docker-compose -f docker-compose.yml rm -f
docker-compose -f docker-compose.yml build test_studio
docker-compose -f docker-compose.yml build test_studio_frontend
docker-compose -f docker-compose.yml run test_studio
docker-compose -f docker-compose.yml run test_studio_frontend
docker-compose -f docker-compose.test.yml down --rmi all --volumes --remove-orphans
docker-compose -f docker-compose.test.yml rm -f
docker-compose -f docker-compose.test.yml build test_studio
docker-compose -f docker-compose.test.yml build test_studio_frontend
docker-compose -f docker-compose.test.yml run test_studio
docker-compose -f docker-compose.test.yml run test_studio_frontend

.PHONY: test_python
test_python:
docker-compose -f docker-compose.yml down --rmi all --volumes --remove-orphans
docker-compose -f docker-compose.yml rm -f
docker-compose -f docker-compose.yml build test_studio
docker-compose -f docker-compose.yml run test_studio
docker-compose -f docker-compose.test.yml down --rmi all --volumes --remove-orphans
docker-compose -f docker-compose.test.yml rm -f
docker-compose -f docker-compose.test.yml build test_studio
docker-compose -f docker-compose.test.yml run test_studio

.PHONY: test_frontend
test_frontend:
docker-compose -f docker-compose.yml down --rmi all --volumes --remove-orphans
docker-compose -f docker-compose.yml rm -f
docker-compose -f docker-compose.yml build test_studio_frontend
docker-compose -f docker-compose.yml run test_studio_frontend
docker-compose -f docker-compose.test.yml down --rmi all --volumes --remove-orphans
docker-compose -f docker-compose.test.yml rm -f
docker-compose -f docker-compose.test.yml build test_studio_frontend
docker-compose -f docker-compose.test.yml run test_studio_frontend

.PHONY: build_frontend
build_frontend:
docker-compose -f docker-compose.yml down --rmi all --volumes --remove-orphans
docker-compose -f docker-compose.yml rm -f
docker-compose -f docker-compose.yml build build_studio_frontend
docker-compose -f docker-compose.yml run build_studio_frontend
docker-compose -f docker-compose.test.yml down --rmi all --volumes --remove-orphans
docker-compose -f docker-compose.test.yml rm -f
docker-compose -f docker-compose.test.yml build build_studio_frontend
docker-compose -f docker-compose.test.yml run build_studio_frontend

.PHONY: docs
docs:
Expand Down
25 changes: 25 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: "3"

services:
studio-dev-be:
build:
context: .
dockerfile: Dockerfile.dev
working_dir: /app
volumes:
- .:/app
ports:
- "8000:8000"
command: python main.py --reload --host 0.0.0.0 --port 8000
environment:
PYTHONPATH: /app/
TZ: Asia/Tokyo

studio-dev-fe:
image: node:16.20.1-alpine
working_dir: /app/frontend
volumes:
- ./frontend/:/app/frontend/
ports:
- "3000:3000"
command: ash -c 'yarn install && yarn start'
37 changes: 37 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: "3.8"

services:
test_studio:
image: test_studio
container_name: test_studio
build:
context: .
dockerfile: Dockerfile.test
environment:
PYTHONPATH: .
TZ: Asia/Tokyo
volumes:
- ./studio:/app/studio
- ./conda/yaml:/app/conda/yaml
- ./studio/test_data:/tmp/studio

test_studio_frontend:
image: test_studio_frontend
container_name: test_studio_frontend
build:
context: ./frontend
dockerfile: Dockerfile.test
environment:
TZ: Asia/Tokyo
command: yarn test:ci

build_studio_frontend:
image: build_studio_frontend
container_name: build_studio_frontend
build:
context: ./frontend
dockerfile: Dockerfile.build
environment:
TZ: Asia/Tokyo
volumes:
- ./frontend/build:/app/build:cached
40 changes: 9 additions & 31 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,14 @@
version: "3.8"
version: "3"

services:
test_studio:
image: test_studio
container_name: test_studio
studio:
build:
context: .
dockerfile: Dockerfile-test
environment:
PYTHONPATH: .
TZ: Asia/Tokyo
volumes:
- ./studio:/app/studio
- ./conda/yaml:/app/conda/yaml
- ./studio/test_data:/tmp/studio

test_studio_frontend:
image: test_studio_frontend
container_name: test_studio_frontend
build:
context: ./frontend
dockerfile: Dockerfile-test
environment:
TZ: Asia/Tokyo
command: yarn test:ci

build_studio_frontend:
image: build_studio_frontend
container_name: build_studio_frontend
build:
context: ./frontend
dockerfile: Dockerfile-build
dockerfile: Dockerfile
working_dir: /app
ports:
- "8000:8000"
command: python main.py --host 0.0.0.0 --port 8000
environment:
PYTHONPATH: /app/
TZ: Asia/Tokyo
volumes:
- ./frontend/build:/app/build:cached
20 changes: 10 additions & 10 deletions docs/installation/docker_for_developer.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,14 @@ git clone https://github.com/oist/optinist.git
cd ./optinist
```

### Build docker image

```
docker build --no-cache -t optinist-dev -f Dockerfile .
```

### Start docker container

```
docker run -it --shm-size=2G --name optinist_dev_container -d -p 8000:8000 --restart=unless-stopped optinist-dev
docker compose -f docker-compose.dev.yml up
```

- add `-d` option to make container run in background

<!--
## 2. Create virtualenv
Expand All @@ -45,8 +40,13 @@ Under maintenance...

## 2. Access to backend

- Launch browser, and go to http://localhost:8000
- Launch browser, and go to http://localhost:3000
- Your local code change will be applied on save.

It opens correctly!
```{eval-rst}
.. note::
dev container uses port 3000,
while production docker image uses 8000.
```

Done!
2 changes: 1 addition & 1 deletion frontend/Dockerfile-build → frontend/Dockerfile.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ ENV GENERATE_SOURCEMAP false

RUN yarn install

CMD yarn build
CMD yarn build
4 changes: 2 additions & 2 deletions frontend/Dockerfile-test → frontend/Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ RUN mkdir /react-app
WORKDIR /react-app

COPY . ./
ENV GENERATE_SOURCEMAP false
RUN yarn install
ENV GENERATE_SOURCEMAP false
RUN yarn install

0 comments on commit cb4e068

Please sign in to comment.