feat(docker): upgrading dockerfiles

This commit is contained in:
Laureηt 2022-02-08 17:35:48 +01:00
parent 77c794c699
commit 29253fba05
No known key found for this signature in database
GPG key ID: D88C6B294FD40994
2 changed files with 41 additions and 29 deletions

View file

@ -1,4 +1,4 @@
FROM python:alpine
FROM python:alpine AS base
# set /code as the work directory
WORKDIR /code
@ -7,19 +7,15 @@ RUN \
# update alpine repositories
apk update \
# build tools dependencies
&& apk add build-base cmake git \
&& apk add --no-cache build-base cmake git \
# mgba dependencies
&& apk add libffi-dev elfutils-dev libzip-tools minizip-dev libedit-dev sqlite-dev libepoxy-dev ffmpeg ffmpeg-dev libpng-dev jpeg-dev \
# install poetry and cffi deps for mgba
&& pip install poetry cffi
# copy poetry config files
COPY ./pyproject.toml /code
&& apk add --no-cache libffi-dev elfutils-dev libzip-tools minizip-dev libedit-dev sqlite-dev libepoxy-dev ffmpeg ffmpeg-dev libpng-dev jpeg-dev \
&& pip install cffi
RUN \
cd /code \
# clone mgba
&& git clone https://github.com/mgba-emu/mgba.git mgba \
&& git clone https://github.com/mgba-emu/mgba.git --branch 0.9 mgba \
# create build directory
&& mkdir mgba/build \
# go to the build directory
@ -28,24 +24,37 @@ RUN \
&& cmake -DBUILD_PYTHON=ON -DBUILD_QT=OFF -DBUILD_SDL=OFF -DUSE_DISCORD_RPC=OFF -DCMAKE_INSTALL_PREFIX:PATH=/usr/local .. \
# build mGBA
&& make \
# install mGBA
# install mGBA, TODO: is install needed ?
&& make install
# copy poetry config file
COPY ./pyproject.toml /code
RUN \
cd /code \
# install poetry
&& pip install poetry \
# config poetry to not create a .venv
&& poetry config virtualenvs.create false \
# upgrade pip
&& poetry run pip install --upgrade pip
RUN \
cd /code/mgba/src/platform/python \
# install mGBA bindings
# install mGBA bindings, TODO: can delete everything else ?
&& BINDIR=/code/mgba/build/include LIBDIR=/code/mgba/build/include python setup.py install
RUN \
# go to the workdir
cd /code/ \
# # config poetry to not create a .venv
&& poetry config virtualenvs.create false \
# # upgrade pip
&& poetry run pip install --upgrade pip \
# install poetry
&& poetry install --no-interaction --no-ansi --no-dev
# copy the src files
COPY ./src /code/src
COPY ./roms/pokemon.gba /code/roms/pokemon.gba
FROM base AS prod
RUN poetry install --no-interaction --no-ansi --no-dev
FROM prod as dev
RUN poetry install --no-interaction --no-ansi
FROM prod AS server
CMD [ "poetry", "run", "python", "src/server.py" ]
FROM prod AS emulator
CMD [ "poetry", "run", "python", "src/emulator.py" ]

View file

@ -1,10 +1,10 @@
version: "3"
version: "3.8"
services:
server:
build:
context: .
entrypoint: poetry run python src/server.py
restart: unless-stopped
dockerfile: Dockerfile
target: server
environment:
- REDIS_HOST=$REDIS_HOST
- REDIS_PORT=$REDIS_PORT
@ -14,12 +14,13 @@ services:
- $WEBSOCKET_PORT:$WEBSOCKET_PORT
depends_on:
- redis
restart: unless-stopped
emulator:
build:
context: .
entrypoint: poetry run python src/emulator.py
restart: unless-stopped
dockerfile: Dockerfile
target: emulator
environment:
- REDIS_HOST=$REDIS_HOST
- REDIS_PORT=$REDIS_PORT
@ -30,15 +31,17 @@ services:
- redis
volumes:
- ./states/:/code/states/
- ./roms/:/code/roms/
restart: unless-stopped
redis:
image: redis:alpine
restart: unless-stopped
ports:
- $REDIS_PORT:6379
restart: unless-stopped
rtmp:
image: tiangolo/nginx-rtmp
restart: unless-stopped
ports:
- $RTMP_PORT:1935
restart: unless-stopped