-
Notifications
You must be signed in to change notification settings - Fork 0
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
Setup docker for project #3
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# The build image | ||
FROM python:3.8.0-slim as builder | ||
RUN apt-get update \ | ||
&& apt-get install gcc python-dev libpq-dev -y \ | ||
&& apt-get clean | ||
|
||
COPY ./requirements.txt /app/requirements.txt | ||
WORKDIR app | ||
RUN pip install --upgrade pip \ | ||
&& pip install --user -r requirements.txt | ||
|
||
COPY . /app | ||
|
||
# The app image | ||
FROM python:3.8.0-slim as app | ||
COPY --from=builder /root/.local /root/.local | ||
COPY --from=builder /app /app | ||
WORKDIR app | ||
RUN apt-get update && apt-get install libpq-dev -y | ||
ENV PATH=/usr/pgsql-9.1/bin/:/root/.local/bin:$PATH | ||
COPY ./contrib/docker/start.sh /start.sh | ||
COPY ./contrib/docker/entrypoint.sh /entrypoint.sh | ||
|
||
RUN chmod +x /entrypoint.sh && \ | ||
chmod +x /start.sh | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] | ||
CMD ["/start.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,26 @@ | ||
# DebunkBot | ||
A bot that debunks claims shared on social media by sharing a fact check. Powered by Google Sheets and the rains in Africa. Accessible at https://debunkbot.codeforafrica.org/ | ||
|
||
## Development | ||
|
||
Gitignore is standardized for this project using [gitignore.io](https://www.gitignore.io/) to support various development platforms. | ||
To get the project up and running: | ||
|
||
- Clone this repo | ||
|
||
### Virtual environment | ||
|
||
- Use virtualenv to create your virtual environment; `virtualenv venv` | ||
- Activate the virtual environment; `source venv/bin/activate` | ||
- Install the requirements; `pip install -r requirements.txt` | ||
- Create a debunkbot database | ||
- Add database connection details to `.env` file, using `.env.sample` as a template | ||
- Migrate the database: `python manage.py migrate` | ||
- Run the server: `python manage.py runserver` | ||
|
||
### Docker | ||
|
||
Using docker compose: | ||
|
||
- Build the project; `docker-compose build` | ||
- Run the project; `docker-compose up -d` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/sh | ||
|
||
if [ "$DATABASE" = "postgres" ] | ||
then | ||
echo "Waiting for postgres..." | ||
|
||
while ! nc -z $SQL_HOST $SQL_PORT; do | ||
sleep 0.1 | ||
done | ||
|
||
echo "PostgreSQL started" | ||
fi | ||
|
||
python manage.py flush --no-input | ||
python manage.py migrate | ||
|
||
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/sh | ||
python manage.py migrate --noinput # Apply database migrations | ||
python manage.py collectstatic --clear --noinput # Collect static files | ||
|
||
# Prepare log files and start outputting logs to stdout | ||
touch /src/logs/gunicorn.log | ||
touch /src/logs/access.log | ||
tail -n 0 -f /src/logs/*.log & | ||
|
||
# Start Gunicorn processes | ||
echo Starting Gunicorn. | ||
exec gunicorn \ | ||
--bind 0.0.0.0:8000 \ | ||
--workers 3 \ | ||
--worker-class gevent \ | ||
--log-level=info \ | ||
--log-file=/src/logs/gunicorn.log \ | ||
--access-logfile=/src/logs/access.log \ | ||
--name debunkbot --reload debunkbot.wsgi:application \ | ||
--chdir debunkbot/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
version: '3.3' | ||
|
||
services: | ||
db: | ||
image: "postgres:12" | ||
hostname: postgres | ||
volumes: | ||
- postgres_data:/var/lib/postgresql/data/ | ||
environment: | ||
- POSTGRES_USER=debunkbot | ||
- POSTGRES_PASSWORD=debunkbot | ||
- POSTGRES_DB=debunkbot | ||
web: | ||
build: | ||
context: . | ||
volumes: | ||
- ./:/src | ||
ports: | ||
- 8000:8000 | ||
env_file: | ||
- ./.env | ||
depends_on: | ||
- db | ||
|
||
volumes: | ||
postgres_data: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to repeat this
libpq-dev
package because apparentlypsycopg2
needs it both to install and to run and I couldn't find a way to copy the packages from thebuild image
to theapp image
. All in all, I was able to bring the final image down to 275MB from around 599MB. I'll keep doing more research concerning thislibpq-dev
package and definitely raise anpatch pr
to fix it when I get a fix.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kilemensi ☝️ cc @KhadijaMahanga
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird but cool @ascii-dev i.e. would have assumed dev packages are only needed to build binaries & hence we should have been able to just copy the built binaries into app image... but we're short on time right now so 300MB reduction is good enough. 🚀