Kaynağa Gözat

Improve containers

pull/426/head
Guillaume Vincent 5 yıl önce
ebeveyn
işleme
407668671c
7 değiştirilmiş dosya ile 41 ekleme ve 31 silme
  1. +9
    -9
      containers/backend/Dockerfile
  2. +3
    -3
      containers/backend/entrypoint.sh
  3. +14
    -5
      containers/docker-compose.yml
  4. +4
    -5
      containers/test.sh
  5. +5
    -3
      containers/webserver/Dockerfile
  6. +5
    -5
      containers/webserver/entrypoint.sh
  7. +1
    -1
      containers/webserver/generate_apache_conf.py

+ 9
- 9
containers/backend/Dockerfile Dosyayı Görüntüle

@@ -3,15 +3,15 @@ FROM python:3.6
LABEL name="LessPass Backend"
LABEL maintainer="LessPass <contact@lesspass.com>"

RUN mkdir /opt/app
WORKDIR /opt/app
RUN python -m venv /opt/app/venv
COPY requirements.txt /opt/app/
RUN /opt/app/venv/bin/python -m pip install --upgrade pip && \
/opt/app/venv/bin/python -m pip install -r requirements.txt
RUN mkdir /app
WORKDIR /app
COPY requirements.txt /app
RUN python -m pip install --upgrade pip
RUN python -m pip install -r requirements.txt

COPY . /opt/app/
COPY . /app
RUN python --version

ENTRYPOINT ["/opt/app/entrypoint.sh"]
ENTRYPOINT ["/app/entrypoint.sh"]

CMD ["/opt/app/venv/bin/gunicorn", "lesspass.wsgi:application", "--access-logfile", "-", "--error-logfile", "-", "--log-level", "debug", "--bind", "0.0.0.0:8000"]
CMD ["gunicorn", "lesspass.wsgi:application", "--access-logfile", "-", "--error-logfile", "-", "--log-level", "debug", "--bind", "0.0.0.0:8000"]

+ 3
- 3
containers/backend/entrypoint.sh Dosyayı Görüntüle

@@ -1,7 +1,7 @@
#!/usr/bin/env bash

/opt/app/venv/bin/python wait_db.py
/opt/app/venv/bin/python manage.py migrate
/opt/app/venv/bin/python manage.py collectstatic --clear --no-input
python wait_db.py
python manage.py migrate
python manage.py collectstatic --clear --no-input

exec "$@"

+ 14
- 5
containers/docker-compose.yml Dosyayı Görüntüle

@@ -1,4 +1,5 @@
version: "3"

services:
db:
image: postgres:9.5
@@ -10,16 +11,24 @@ services:
- '8000'
links:
- db
env_file:
- .env
environment:
- DATABASE_ENGINE
- DATABASE_HOST
- DATABASE_NAME
- DATABASE_PASSWORD
- DATABASE_PORT
- DATABASE_USER
- DEBUG
- SECRET_KEY
webserver:
build: ./webserver
ports:
- 80:80
- 443:443
env_file:
- .env
volumes:
- ./webserver/ssl:/opt/app/ssl
- ./webserver/ssl:/app/ssl
environment:
- FQDN

volumes:
postgresql:

+ 4
- 5
containers/test.sh Dosyayı Görüntüle

@@ -4,9 +4,8 @@ set -e
# containers
export COMPOSE_PROJECT_NAME=lesspass
docker-compose build
docker-compose down -v
docker-compose up -d
date -u
docker exec -it lesspass_backend_1 sh -c '/opt/app/venv/bin/python wait_db.py'
date -u
docker exec -it lesspass_backend_1 sh -c '/opt/app/venv/bin/python manage.py test'
docker-compose down
docker exec -it lesspass_backend_1 sh -c 'python wait_db.py'
docker exec -it lesspass_backend_1 sh -c 'python manage.py test'
docker-compose down -v

+ 5
- 3
containers/webserver/Dockerfile Dosyayı Görüntüle

@@ -5,8 +5,10 @@ LABEL maintainer="LessPass <contact@lesspass.com>"

RUN apt-get update && apt-get install -y \
python3 \
python3-jinja2
python3-jinja2 \
openssl \
&& rm -rf /var/lib/apt/lists/*

COPY . /opt/app/
COPY . /app

ENTRYPOINT ["/opt/app/entrypoint.sh"]
ENTRYPOINT ["/app/entrypoint.sh"]

+ 5
- 5
containers/webserver/entrypoint.sh Dosyayı Görüntüle

@@ -4,23 +4,23 @@ create_wildcard_certificate () {
openssl req -x509 -newkey rsa:4096 -nodes -keyout ${1}.key -out ${1}.crt -days 365 -subj "/C=FR/ST=Gironde/L=Bordeaux/O=LessPass/OU=LessPass/CN=*.${1}"
}

if [[ ! -f /opt/app/ssl/${FQDN}.crt || ! -f /opt/app/ssl/${FQDN}.key ]]; then
if [[ ! -f /app/ssl/${FQDN}.crt || ! -f /app/ssl/${FQDN}.key ]]; then
echo "${FQDN}.crt or ${FQDN}.key not found! Generate wildcard certificate"
cd /opt/app/ssl
cd /app/ssl
create_wildcard_certificate ${FQDN}
fi

mkdir -p /etc/httpd/ssl
chmod 755 /etc/httpd/ssl
cp /opt/app/ssl/${FQDN}.crt /etc/httpd/ssl/
cp /app/ssl/${FQDN}.crt /etc/httpd/ssl/
chmod 644 /etc/httpd/ssl/${FQDN}.crt

mkdir -p /etc/httpd/ssl/private
chmod 710 /etc/httpd/ssl/private
cp /opt/app/ssl/${FQDN}.key /etc/httpd/ssl/private/
cp /app/ssl/${FQDN}.key /etc/httpd/ssl/private/
chmod 640 /etc/httpd/ssl/private/${FQDN}.key

/opt/app/venv/bin/python /opt/app/generate_apache_conf.py
python /app/generate_apache_conf.py

cat /etc/httpd/conf.d/lesspass.conf


+ 1
- 1
containers/webserver/generate_apache_conf.py Dosyayı Görüntüle

@@ -12,6 +12,6 @@ if __name__ == "__main__":
"DEBUG": os.environ.get("DEBUG", "0") == "1",
}
print(context)
jinja_template = Template(open("/opt/app/lesspass.conf.j2").read())
jinja_template = Template(open("/app/lesspass.conf.j2").read())
with open("/etc/httpd/conf.d/lesspass.conf", "w") as f:
f.write(jinja_template.render(context))

Yükleniyor…
İptal
Kaydet