Skip to content

Ycv 154 integrate docker container poc #652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/node_modules
ve
57 changes: 57 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
FROM ubuntu:20.04
ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y wget curl tar nano make npm python3.8 python3.8-venv python3-pip nginx

# Download Node.js tarball
RUN curl -o node.tar.gz -L https://nodejs.org/download/release/v18.16.0/node-v18.16.0-linux-x64.tar.gz

# Extract Node.js
RUN tar xzf node.tar.gz --strip-components=1 -C /usr/local

# Cleanup
RUN rm node.tar.gz

# Add Node.js to PATH
ENV PATH="/usr/local/bin:${PATH}"

# Verify installation
RUN node --version && npm --version
# ENV PATH=”/node-v18.16.0-linux-x64/bin:${PATH}”
# RUN node -v

# Download and extract Redis source code
RUN wget http://download.redis.io/releases/redis-5.0.7.tar.gz && \
tar xzf redis-5.0.7.tar.gz

# Build Redis
RUN cd redis-5.0.7 && \
make

# Install Redis
RUN cd redis-5.0.7 && \
make install

# Cleanup unnecessary files
RUN rm -rf redis-5.0.7.tar.gz redis-5.0.7

# Create Django App
RUN mkdir -p /app
WORKDIR /app

# Add Django App
COPY . .
RUN rm -rf /ve

# Install node packages for svelte
RUN npm install

# Configure Nginx reverse-proxy to work with our current make configuration
COPY nginx.docker.conf /etc/nginx/sites-available/default

# Expose port 80 for Nginx
EXPOSE 80
EXPOSE 8000
EXPOSE 8125

CMD ["make", "runserver"]
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,24 @@ npm run dev
Or, make a one-time production build of the applcation with `npm run build`.

Both of these commands will update the compiled JS at `media/mathplayground/build/`.

### Using Docker in Develo0pment

# What's included
`.dockerignore` - This files is used to ignore anything you don't want to be copied inside the docker image
`Dockerfile` - The docker image instructions of what to include to build the image.
`nginx.docker.conf` - The nginx instructions inside docker for reverse proxy to mimic our infrastructure setup, this is copied to the docker image when built

# Versions
- ubuntu 20.04 base image
- redis 5.0.7 (which is used in production)
- node 18.16.0 (which is used in Jenkins during our build process)
- python 3.8.10

# Running docker
Run `docker compose -f docker-compose.dev.yml up` to start the containers in your terminal. These instructions are unique for using it for development purpose because the `volumnes` are mapped to your local directory. Any changes that is made locally will reflect directly inside the container.

** Currently only working for Django
** TODO: Fix Svelte hot module re-loading from within docker container


52 changes: 52 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
version: '3.8'
services:
postgres:
image: postgres:13.11-alpine
container_name: 3demos_postgres
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
ports:
- '5432:5432'
volumes:
- pgdata:/var/lib/postgresql/data
# redis:
# image: redis:5.0.7-alpine
# container_name: 3demos_redis
# restart: always
# ports:
# - '6379:6379'
# volumes:
# - redisdata:/data
django:
container_name: 3demos_app
build:
context: .
dockerfile: Dockerfile
links:
- postgres:postgres
# - redis:redis
ports:
- 80:80
- 8000:8000
- 8125:8125
# - 8000:8000 # Daphne Web for websockets
command:
- /bin/bash
- -c
- |
service nginx start
# mkdir /var/log/django
# touch /var/log/django/mathplayground.log
nohup redis-server &
npm run build
make runserver
# npm run dev
volumes:
- ./media/src:/app/media/src/
- ./mathplayground:/app/mathplayground
- ./node_modules:/app/node_modules
volumes:
pgdata:
# redisdata:
101 changes: 101 additions & 0 deletions nginx.docker.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
listen 80;
server_name localhost;

location / {
proxy_pass http://localhost:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# listen 80 default_server;
#listen [::]:80 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

# root /var/www/html;

# Add index.php to the list if you are using PHP
# index index.html index.htm index.nginx-debian.html;

# server_name _;

# location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
# }

# pass PHP scripts to FastCGI server
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
# fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}