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 # set /code as the work directory
WORKDIR /code WORKDIR /code
@ -7,19 +7,15 @@ RUN \
# update alpine repositories # update alpine repositories
apk update \ apk update \
# build tools dependencies # build tools dependencies
&& apk add build-base cmake git \ && apk add --no-cache build-base cmake git \
# mgba dependencies # 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 \ && 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 \
# install poetry and cffi deps for mgba && pip install cffi
&& pip install poetry cffi
# copy poetry config files
COPY ./pyproject.toml /code
RUN \ RUN \
cd /code \ cd /code \
# clone mgba # 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 # create build directory
&& mkdir mgba/build \ && mkdir mgba/build \
# go to the build directory # 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 .. \ && cmake -DBUILD_PYTHON=ON -DBUILD_QT=OFF -DBUILD_SDL=OFF -DUSE_DISCORD_RPC=OFF -DCMAKE_INSTALL_PREFIX:PATH=/usr/local .. \
# build mGBA # build mGBA
&& make \ && make \
# install mGBA # install mGBA, TODO: is install needed ?
&& make install && 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 \ RUN \
cd /code/mgba/src/platform/python \ 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 && 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 the src files
COPY ./src /code/src 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: services:
server: server:
build: build:
context: . context: .
entrypoint: poetry run python src/server.py dockerfile: Dockerfile
restart: unless-stopped target: server
environment: environment:
- REDIS_HOST=$REDIS_HOST - REDIS_HOST=$REDIS_HOST
- REDIS_PORT=$REDIS_PORT - REDIS_PORT=$REDIS_PORT
@ -14,12 +14,13 @@ services:
- $WEBSOCKET_PORT:$WEBSOCKET_PORT - $WEBSOCKET_PORT:$WEBSOCKET_PORT
depends_on: depends_on:
- redis - redis
restart: unless-stopped
emulator: emulator:
build: build:
context: . context: .
entrypoint: poetry run python src/emulator.py dockerfile: Dockerfile
restart: unless-stopped target: emulator
environment: environment:
- REDIS_HOST=$REDIS_HOST - REDIS_HOST=$REDIS_HOST
- REDIS_PORT=$REDIS_PORT - REDIS_PORT=$REDIS_PORT
@ -30,15 +31,17 @@ services:
- redis - redis
volumes: volumes:
- ./states/:/code/states/ - ./states/:/code/states/
- ./roms/:/code/roms/
restart: unless-stopped
redis: redis:
image: redis:alpine image: redis:alpine
restart: unless-stopped
ports: ports:
- $REDIS_PORT:6379 - $REDIS_PORT:6379
restart: unless-stopped
rtmp: rtmp:
image: tiangolo/nginx-rtmp image: tiangolo/nginx-rtmp
restart: unless-stopped
ports: ports:
- $RTMP_PORT:1935 - $RTMP_PORT:1935
restart: unless-stopped