mirror of
https://github.com/taroved/pol
synced 2025-05-21 00:20:22 -07:00
Merge pull request #32 from marlluslustosa/master
Dockerize the project
This commit is contained in:
commit
c2a3b1a7c7
27
Dockerfile
Normal file
27
Dockerfile
Normal file
@ -0,0 +1,27 @@
|
||||
FROM ubuntu:bionic as builder
|
||||
|
||||
RUN echo 'APT::Install-Recommends 0;' >> /etc/apt/apt.conf.d/01norecommends \
|
||||
&& echo 'APT::Install-Suggests 0;' >> /etc/apt/apt.conf.d/01norecommends \
|
||||
&& apt-get update \
|
||||
&& DEBIAN_FRONTEND=noninteractive apt-get install -y bash vim.tiny wget sudo net-tools ca-certificates unzip apt-transport-https \
|
||||
&& DEBIAN_FRONTEND=noninteractive apt-get install -y python-minimal libmysqlclient-dev libxml2-dev libxslt-dev python-dev libffi-dev gcc libssl-dev gettext \
|
||||
&& DEBIAN_FRONTEND=noninteractive apt-get install -y python-pip python-setuptools nodejs node-gyp npm ruby nginx \
|
||||
&& pip install --upgrade pip \
|
||||
&& npm install -g less@2.7.1 \
|
||||
&& npm install -g yuglify@0.1.4 \
|
||||
&& gem install sass -v 3.4.22
|
||||
|
||||
WORKDIR /app
|
||||
ADD . .
|
||||
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
RUN cp ./nginx/default.site-example /etc/nginx/sites-available/default \
|
||||
&& cp ./frontend/frontend/settings.py.example ./frontend/frontend/settings.py
|
||||
|
||||
RUN cd /var/lib/gems/2.5.0/gems/sass-3.4.22/lib/sass/ \
|
||||
&& sed -i "s/when\ Fixnum/when\ Integer/" util.rb
|
||||
|
||||
WORKDIR ./frontend
|
||||
|
||||
ENTRYPOINT ["/bin/bash", "start.sh"]
|
42
docker-compose.yaml
Normal file
42
docker-compose.yaml
Normal file
@ -0,0 +1,42 @@
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
politepol:
|
||||
build:
|
||||
context: .
|
||||
environment:
|
||||
DB_NAME: 'politepol'
|
||||
DB_USER: 'rooooooooooot'
|
||||
DB_PASSWORD: 'toooooooooooor'
|
||||
DB_HOST: 'dbpolitepol'
|
||||
DB_PORT: '3306'
|
||||
WEB_PORT: '8088'
|
||||
TIME_ZONE: 'America\/Fortaleza'
|
||||
image: politepol:latest
|
||||
depends_on:
|
||||
- 'dbpolitepol'
|
||||
command: ["./wait-for-it.sh", "db:3306", "--", "/bin/bash", "./frontend/start.sh"]
|
||||
container_name: politepol
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- politepol-network
|
||||
ports:
|
||||
- '8088:8088'
|
||||
|
||||
dbpolitepol:
|
||||
image: mysql:5.7
|
||||
container_name: dbpolitepol
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
MYSQL_DATABASE: 'politepol'
|
||||
MYSQL_USER: 'rooooooooooot'
|
||||
MYSQL_PASSWORD: 'toooooooooooor'
|
||||
MYSQL_ROOT_PASSWORD: 'rootpass'
|
||||
networks:
|
||||
- politepol-network
|
||||
volumes:
|
||||
- ./mysql:/var/lib/mysql
|
||||
|
||||
networks:
|
||||
politepol-network:
|
||||
driver: 'bridge'
|
22
frontend/start.sh
Normal file
22
frontend/start.sh
Normal file
@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
sed -i -E -e "s/(DEBUG = ).*/\1True/" \
|
||||
-e "s/('NAME': ')pol(',)/\1${DB_NAME}\2/" \
|
||||
-e "s/('USER': ')root(',)/\1${DB_USER}\2/" \
|
||||
-e "s/('PASSWORD': ')toor(',)/\1${DB_PASSWORD}\2/" \
|
||||
-e "s/('HOST': ')127\.0\.0\.1(',)/\1${DB_HOST}\2/" \
|
||||
-e "s/('PORT': ')3306(',)/\1${DB_PORT}\2/" \
|
||||
-e "s/(TIME_ZONE = ').*/\1${TIME_ZONE}'/" \
|
||||
./frontend/settings.py
|
||||
|
||||
sed -i -e 's/listen\ 80/listen\ '${WEB_PORT}'/g' \
|
||||
-e 's/\[::\]:80/\[::\]:'${WEB_PORT}'/g' /etc/nginx/sites-available/default \
|
||||
&& service nginx reload
|
||||
|
||||
service nginx start > /dev/null
|
||||
|
||||
/usr/bin/python manage.py migrate
|
||||
/usr/bin/python manage.py loaddata fields.json
|
||||
|
||||
/usr/bin/python ../downloader.py &
|
||||
/usr/bin/python manage.py runserver
|
@ -7,12 +7,13 @@ server {
|
||||
server_name _;
|
||||
|
||||
location / {
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_pass http://127.0.0.1:8000;
|
||||
}
|
||||
|
||||
location /downloader {
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_pass http://127.0.0.1:1234;
|
||||
proxy_pass http://127.0.0.1:1234;
|
||||
}
|
||||
|
||||
location /feed {
|
||||
|
13
readme.md
13
readme.md
@ -94,6 +94,19 @@ python manage.py runserver
|
||||
popd
|
||||
```
|
||||
|
||||
# Installation of Docker
|
||||
|
||||
## Build
|
||||
```
|
||||
git clone https://github.com/taroved/pol
|
||||
cd pol
|
||||
docker-compose up -d --build
|
||||
```
|
||||
|
||||
## Access (port 8088)
|
||||
Docker Host IP in browser. Ex:
|
||||
http://192.168.0.10:8088
|
||||
|
||||
|
||||
## License
|
||||
|
||||
|
178
wait-for-it.sh
Normal file
178
wait-for-it.sh
Normal file
@ -0,0 +1,178 @@
|
||||
#!/usr/bin/env bash
|
||||
# Use this script to test if a given TCP host/port are available
|
||||
|
||||
WAITFORIT_cmdname=${0##*/}
|
||||
|
||||
echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }
|
||||
|
||||
usage()
|
||||
{
|
||||
cat << USAGE >&2
|
||||
Usage:
|
||||
$WAITFORIT_cmdname host:port [-s] [-t timeout] [-- command args]
|
||||
-h HOST | --host=HOST Host or IP under test
|
||||
-p PORT | --port=PORT TCP port under test
|
||||
Alternatively, you specify the host and port as host:port
|
||||
-s | --strict Only execute subcommand if the test succeeds
|
||||
-q | --quiet Don't output any status messages
|
||||
-t TIMEOUT | --timeout=TIMEOUT
|
||||
Timeout in seconds, zero for no timeout
|
||||
-- COMMAND ARGS Execute command with args after the test finishes
|
||||
USAGE
|
||||
exit 1
|
||||
}
|
||||
|
||||
wait_for()
|
||||
{
|
||||
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
|
||||
echoerr "$WAITFORIT_cmdname: waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
|
||||
else
|
||||
echoerr "$WAITFORIT_cmdname: waiting for $WAITFORIT_HOST:$WAITFORIT_PORT without a timeout"
|
||||
fi
|
||||
WAITFORIT_start_ts=$(date +%s)
|
||||
while :
|
||||
do
|
||||
if [[ $WAITFORIT_ISBUSY -eq 1 ]]; then
|
||||
nc -z $WAITFORIT_HOST $WAITFORIT_PORT
|
||||
WAITFORIT_result=$?
|
||||
else
|
||||
(echo > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1
|
||||
WAITFORIT_result=$?
|
||||
fi
|
||||
if [[ $WAITFORIT_result -eq 0 ]]; then
|
||||
WAITFORIT_end_ts=$(date +%s)
|
||||
echoerr "$WAITFORIT_cmdname: $WAITFORIT_HOST:$WAITFORIT_PORT is available after $((WAITFORIT_end_ts - WAITFORIT_start_ts)) seconds"
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
return $WAITFORIT_result
|
||||
}
|
||||
|
||||
wait_for_wrapper()
|
||||
{
|
||||
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
|
||||
if [[ $WAITFORIT_QUIET -eq 1 ]]; then
|
||||
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --quiet --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
|
||||
else
|
||||
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
|
||||
fi
|
||||
WAITFORIT_PID=$!
|
||||
trap "kill -INT -$WAITFORIT_PID" INT
|
||||
wait $WAITFORIT_PID
|
||||
WAITFORIT_RESULT=$?
|
||||
if [[ $WAITFORIT_RESULT -ne 0 ]]; then
|
||||
echoerr "$WAITFORIT_cmdname: timeout occurred after waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
|
||||
fi
|
||||
return $WAITFORIT_RESULT
|
||||
}
|
||||
|
||||
# process arguments
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
case "$1" in
|
||||
*:* )
|
||||
WAITFORIT_hostport=(${1//:/ })
|
||||
WAITFORIT_HOST=${WAITFORIT_hostport[0]}
|
||||
WAITFORIT_PORT=${WAITFORIT_hostport[1]}
|
||||
shift 1
|
||||
;;
|
||||
--child)
|
||||
WAITFORIT_CHILD=1
|
||||
shift 1
|
||||
;;
|
||||
-q | --quiet)
|
||||
WAITFORIT_QUIET=1
|
||||
shift 1
|
||||
;;
|
||||
-s | --strict)
|
||||
WAITFORIT_STRICT=1
|
||||
shift 1
|
||||
;;
|
||||
-h)
|
||||
WAITFORIT_HOST="$2"
|
||||
if [[ $WAITFORIT_HOST == "" ]]; then break; fi
|
||||
shift 2
|
||||
;;
|
||||
--host=*)
|
||||
WAITFORIT_HOST="${1#*=}"
|
||||
shift 1
|
||||
;;
|
||||
-p)
|
||||
WAITFORIT_PORT="$2"
|
||||
if [[ $WAITFORIT_PORT == "" ]]; then break; fi
|
||||
shift 2
|
||||
;;
|
||||
--port=*)
|
||||
WAITFORIT_PORT="${1#*=}"
|
||||
shift 1
|
||||
;;
|
||||
-t)
|
||||
WAITFORIT_TIMEOUT="$2"
|
||||
if [[ $WAITFORIT_TIMEOUT == "" ]]; then break; fi
|
||||
shift 2
|
||||
;;
|
||||
--timeout=*)
|
||||
WAITFORIT_TIMEOUT="${1#*=}"
|
||||
shift 1
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
WAITFORIT_CLI=("$@")
|
||||
break
|
||||
;;
|
||||
--help)
|
||||
usage
|
||||
;;
|
||||
*)
|
||||
echoerr "Unknown argument: $1"
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ "$WAITFORIT_HOST" == "" || "$WAITFORIT_PORT" == "" ]]; then
|
||||
echoerr "Error: you need to provide a host and port to test."
|
||||
usage
|
||||
fi
|
||||
|
||||
WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15}
|
||||
WAITFORIT_STRICT=${WAITFORIT_STRICT:-0}
|
||||
WAITFORIT_CHILD=${WAITFORIT_CHILD:-0}
|
||||
WAITFORIT_QUIET=${WAITFORIT_QUIET:-0}
|
||||
|
||||
# check to see if timeout is from busybox?
|
||||
WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
|
||||
WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH)
|
||||
if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
|
||||
WAITFORIT_ISBUSY=1
|
||||
WAITFORIT_BUSYTIMEFLAG="-t"
|
||||
|
||||
else
|
||||
WAITFORIT_ISBUSY=0
|
||||
WAITFORIT_BUSYTIMEFLAG=""
|
||||
fi
|
||||
|
||||
if [[ $WAITFORIT_CHILD -gt 0 ]]; then
|
||||
wait_for
|
||||
WAITFORIT_RESULT=$?
|
||||
exit $WAITFORIT_RESULT
|
||||
else
|
||||
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
|
||||
wait_for_wrapper
|
||||
WAITFORIT_RESULT=$?
|
||||
else
|
||||
wait_for
|
||||
WAITFORIT_RESULT=$?
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $WAITFORIT_CLI != "" ]]; then
|
||||
if [[ $WAITFORIT_RESULT -ne 0 && $WAITFORIT_STRICT -eq 1 ]]; then
|
||||
echoerr "$WAITFORIT_cmdname: strict mode, refusing to execute subprocess"
|
||||
exit $WAITFORIT_RESULT
|
||||
fi
|
||||
exec "${WAITFORIT_CLI[@]}"
|
||||
else
|
||||
exit $WAITFORIT_RESULT
|
||||
fi
|
Loading…
x
Reference in New Issue
Block a user