Skip to content

Commit

Permalink
fix: dockerization almost done
Browse files Browse the repository at this point in the history
  • Loading branch information
ivopr committed May 18, 2023
1 parent cb720da commit 2a4c2ba
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 60 deletions.
2 changes: 2 additions & 0 deletions apps/client/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.contentlayer
.next
node_modules
Dockerfile
.dockerignore
20 changes: 4 additions & 16 deletions apps/client/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ WORKDIR /app

# Install dependencies based on the preferred package manager
COPY package.json ./
RUN yarn generate-lock-entry
RUN yarn --frozen-lockfile


Expand All @@ -19,6 +18,7 @@ COPY . .
COPY --from=deps /app/node_modules ./node_modules

RUN yarn prisma generate
RUN yarn content

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
Expand All @@ -30,20 +30,8 @@ RUN yarn build
# If using npm comment out above and use below instead
# RUN npm run build

# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

ENV NODE_ENV production
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED 1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
EXPOSE 3001

COPY --from=builder /app/public ./public
ENV PORT 3001

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
CMD ["yarn", "start"]
8 changes: 0 additions & 8 deletions apps/client/src/lib/api.ts

This file was deleted.

8 changes: 8 additions & 0 deletions apps/client/src/lib/api.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import axios from "axios";

export const api = axios.create({
baseURL:
typeof window === "undefined"
? "http://server:3002/api/v1"
: "http://localhost:3002/api/v1"
});
4 changes: 3 additions & 1 deletion apps/server/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
__pycache__
.venv
flower
flower
Dockerfile
.dockerignore
24 changes: 8 additions & 16 deletions apps/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM python:3.10-alpine as python-base
RUN apk add bind-tools

# https://python-poetry.org/docs#ci-recommendations
ENV POETRY_VERSION=1.4.2
Expand All @@ -16,15 +17,11 @@ RUN python3 -m venv $POETRY_VENV \
&& $POETRY_VENV/bin/pip install -U pip setuptools \
&& $POETRY_VENV/bin/pip install poetry==${POETRY_VERSION}

# Create a new stage from the base python image
FROM python-base as deps

# Copy Poetry to app image
COPY --from=poetry-base ${POETRY_VENV} ${POETRY_VENV}

# Add Poetry to PATH
ENV PATH="${PATH}:${POETRY_VENV}/bin"

# Create a new stage from the base python image
FROM poetry-base as deps
WORKDIR /app

# Copy Dependencies
Expand All @@ -37,18 +34,13 @@ RUN poetry check
# Install Dependencies
RUN poetry install --no-interaction

FROM python-base as builder
FROM deps as runner
WORKDIR /app

# Copy Poetry to app image
COPY --from=poetry-base ${POETRY_VENV} ${POETRY_VENV}

# Add Poetry to PATH
ENV PATH="${PATH}:${POETRY_VENV}/bin"

COPY --from=deps /app /app

# Copy Application
COPY ./server /app/server/
COPY ./app.py /app/
COPY ./.env /app/

EXPOSE 3002

CMD ["poetry", "run", "python", "app.py"]
2 changes: 1 addition & 1 deletion apps/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@


if __name__ == "__main__":
app.run()
app.run(port=3002, host="0.0.0.0")
6 changes: 1 addition & 5 deletions apps/server/server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@

class Config(object):
SECRET_KEY = os.environ.get("VISUAL_DYNAMICS_SECRET_KEY")
UPLOAD_FOLDER = (
os.path.abspath(os.path.join(basedir, "../../..", "VDfiles"))
if os.environ.get("FLASK_DEBUG")
else os.path.abspath(os.path.join(os.path.expanduser("~"), "VDfiles"))
)
UPLOAD_FOLDER = os.path.abspath("/VDfiles")
STATIC_FOLDER = os.path.abspath(os.path.join(basedir, "static"))
MDP_LOCATION_FOLDER = os.path.abspath(os.path.join(STATIC_FOLDER, "mdp"))
SOCK_SERVER_OPTIONS = {"ping_interval": 25}
6 changes: 1 addition & 5 deletions apps/server/server/resources/run/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from celery import uuid
from server.celery_tasks import run_commands
from server.config import Config
from urllib.parse import urlparse


class RunDynamic(Resource):
Expand All @@ -15,10 +14,7 @@ def post(self):

args = parser.parse_args()

url = urlparse(request.base_url).hostname

if os.environ.get("FLASK_DEBUG"):
url = "localhost:3000"
url = "VDWEB:3001"

# Get absolute path to run folder
folder = os.path.abspath(args["folder"])
Expand Down
21 changes: 13 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,29 @@ services:
build:
context: ./apps/client
target: builder
command: yarn start
expose:
- "3001"
networks:
- def
depends_on:
- database
ports:
- "3001:3001"
server:
container_name: VDSRV
restart: always
build:
context: ./apps/server
target: builder
target: runner
depends_on:
- mq
networks:
- def
volumes:
- $HOME/VDfiles:/VDfiles
command: poetry run flask run --host="0.0.0.0" --port=3002
expose:
- "3002"
ports:
- "3002:3002"
volumes:
mq:
driver: local
driver: local
networks:
def:
driver: bridge

0 comments on commit 2a4c2ba

Please sign in to comment.