Skip to content

Commit 9a23a78

Browse files
phackskraynel
authored andcommitted
Setup heroku.yml
1 parent 7e65865 commit 9a23a78

18 files changed

+122
-35
lines changed

.profile.d/heroku-exec.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
3+
# see https://devcenter.heroku.com/articles/exec#enabling-docker-support
4+
[ -z "$SSH_CLIENT" ] && source <(curl --fail --retry 3 -sSL "$HEROKU_EXEC_URL")

devops/deployment/base/Dockerfile Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ FROM node:8.12 AS node
44

55
WORKDIR /code
66

7-
COPY .src/frontend /code/
7+
COPY ./frontend /code/
88
ENV NODE_PATH /code/src
99
RUN yarn
1010
RUN yarn build
@@ -21,7 +21,7 @@ WORKDIR /code
2121

2222
RUN pip install pipenv gunicorn
2323

24-
COPY .src/backend /code/
24+
COPY ./backend /code/
2525
COPY --from=node /code/build /code/front/static/front
2626

2727
RUN pipenv install --system --deploy

Dockerfile.heroku.backend

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# First stage: build front app
2+
FROM node:8.12 AS node
3+
4+
WORKDIR /code
5+
6+
COPY ./frontend /code/
7+
ENV NODE_PATH /code/src
8+
RUN yarn
9+
RUN yarn build
10+
11+
12+
FROM python:3.7
13+
14+
RUN apt-get update && apt-get install -y \
15+
bash \
16+
curl \
17+
openssh-server \
18+
openssh-client
19+
20+
ADD ./.profile.d /app/.profile.d
21+
RUN chmod a+x /app/.profile.d/heroku-exec.sh
22+
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
23+
24+
ADD ./sh-wrapper.sh /bin/sh-wrapper.sh
25+
RUN chmod a+x /bin/sh-wrapper.sh
26+
RUN rm /bin/sh && ln -s /bin/sh-wrapper.sh /bin/sh
27+
28+
ENV DJANGO_SETTINGS_MODULE root.settings.prod
29+
ENV PYTHONPATH /code
30+
ENV CELERY_BROKER_URL sqs://
31+
32+
WORKDIR /code
33+
34+
RUN pip install pipenv gunicorn
35+
36+
COPY ./backend /code/
37+
COPY --from=node /code/build /code/front/static/front
38+
39+
RUN pipenv install --system --deploy
40+
41+
# Collect statics
42+
RUN mkdir -p /var/log/falco
43+
RUN touch /var/log/falco/django.log
44+
45+
COPY ./release_backend.sh /code/
46+
COPY ./start_backend.sh /code/

app.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "falco-nicolasgo",
3+
"description": "A Heroku version of Falco",
4+
"repository": "https://github.com/theodo/falco",
5+
"logo": "https://upload.wikimedia.org/wikipedia/commons/c/c5/Nginx_logo.svg",
6+
"keywords": ["nginx", "docker", "proxy"],
7+
"stack": "container"
8+
}
File renamed without changes.

backend/root/celery.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# set the default Django settings module for the 'celery' program.
88
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "root.settings.dev")
99

10-
broker_url = os.environ["CELERY_BROKER_URL"]
10+
broker_url = os.environ["REDIS_URL"]
1111

1212
app = Celery("root", broker=broker_url)
1313
# Using a string here means the worker doesn't have to serialize

devops/deployment/backend/Dockerfile

-5
This file was deleted.

devops/deployment/backend/start.sh

-9
This file was deleted.
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM falco/base
1+
FROM base
22

3-
COPY ./celerybeat/start_beat.sh /code/
3+
COPY ./start_beat.sh /code/
44
CMD ["sh", "/code/start_beat.sh"]
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM falco/base
1+
FROM base
22

33
COPY ./celeryworker/start_worker.sh /code/
44
CMD ["sh", "/code/start_worker.sh"]

devops/deployment/static/Dockerfile

-11
This file was deleted.

docker-compose.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
- ./postgres-data:/var/lib/postgresql/data
1010

1111
backend:
12-
build: ./backend
12+
build: ./backend/Dockerfile.local
1313
command: python /code/manage.py rundebugserver 0.0.0.0:80
1414
volumes:
1515
- ./backend:/code
@@ -28,7 +28,7 @@ services:
2828
image: redis
2929

3030
celeryworker:
31-
build: ./backend
31+
build: ./backend/Dockerfile.local
3232
volumes:
3333
- ./backend:/code
3434
links:
@@ -41,7 +41,7 @@ services:
4141
command: python /code/manage.py celery
4242

4343
celerybeat:
44-
build: ./backend
44+
build: ./backend/Dockerfile.local
4545
volumes:
4646
- ./backend:/code
4747
links:

frontend/Dockerfile.heroku.static

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# First stage: collect static files in base image
2+
FROM node:8.12 AS node
3+
4+
5+
WORKDIR /code
6+
7+
COPY . /code/
8+
ENV NODE_PATH /code/src
9+
RUN yarn
10+
RUN yarn build
11+
12+
13+
# Second stage: static files server
14+
FROM nginx:1.15
15+
16+
# Custom config
17+
RUN rm /etc/nginx/conf.d/default.conf
18+
COPY .nginx.conf /etc/nginx/conf.d/falco.conf
19+
20+
COPY /code/static /static

devops/deployment/static/nginx.conf frontend/nginx.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
server {
2-
listen 80;
2+
listen $PORT;
33
server_name localhost;
44

55
location /health {

heroku.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
setup:
2+
addons:
3+
- plan: heroku-postgresql
4+
as: DATABASE
5+
- plan: heroku-redis
6+
as: REDIS
7+
build:
8+
docker:
9+
web: Dockerfile.heroku.backend
10+
# static: frontend/Dockerfile.heroku.frontend
11+
# celeryworker: devops/deployment/celeryworker/Dockerfile
12+
# celerybeat: devops/deployment/celerybeat/Dockerfile
13+
release:
14+
image: web
15+
command:
16+
- ./release_backend.sh
17+
run:
18+
web: ./start_backend.sh

release_backend.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cd /code
2+
3+
SECRET_KEY=itdoesntreallymatter LOG_PATH=/var/log/falco/django.log python ./manage.py collectstatic
4+
5+
# Migrate
6+
python ./manage.py migrate --noinput
7+
8+
# Create cache table
9+
python ./manage.py createcachetable
10+
11+

sh-wrapper.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#! /bin/bash
2+
/bin/bash "$@"

start_backend.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cd /code
2+
3+
gunicorn --bind 0.0.0.0:${PORT} --chdir /code --workers 2 --access-logfile /var/log/falco/gunicorn-access.log --error-logfile /var/log/falco/gunicorn-error.log -c root/gunicorn.py root.wsgi:application

0 commit comments

Comments
 (0)