Skip to content
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

Docker deploy #774

Merged
merged 37 commits into from
Nov 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
bc9e950
Merge pull request #3 from vas3k/master
glader Oct 15, 2021
9a54ce7
cleanup: remove "pain" post type (#742)
glader Oct 16, 2021
af29971
Increase "ban_reason" length
vas3k Oct 22, 2021
578392e
Disable comments auto-subscription
vas3k Oct 23, 2021
67e4d70
feat: Badges (#704)
vas3k Oct 23, 2021
1231eba
fix: badge notifications + typos
vas3k Oct 23, 2021
4c50ee3
feat: show subscription duration in profile (#733)
kedMertens Oct 23, 2021
31a3ff1
feat: Remove sending limits for friend's comments
vas3k Oct 23, 2021
1664d47
Threads now public
vas3k Oct 23, 2021
1cffb28
Fix #753. Add badges to /stats/ page
vas3k Oct 23, 2021
8630fa1
fix: Increase latest_badges on stats to 20
vas3k Oct 23, 2021
7f4e4c3
Add "align-items: center;" to stats/badges
vas3k Oct 23, 2021
77778e1
feat: exclude replies from friends notifications
vas3k Oct 26, 2021
c488a18
fix: bad gradient of badges block (#760)
dmitvitalii Oct 29, 2021
411d43f
Add highlight to badged comments, improve CSS
vas3k Oct 29, 2021
c9a2d27
Cooking achievements (#755)
devcooch Oct 29, 2021
77c2813
feat: add socialism and anarchism to list of tags (#637)
ivmirx Oct 29, 2021
89b1c7f
feat: remove "libertarianism" and "anarchism" tags
vas3k Oct 29, 2021
b9178b8
fix: mobile CSS bugs
vas3k Oct 29, 2021
20f6f13
feat: remove expertise from profile, move achievements
vas3k Oct 29, 2021
8bca677
fix #764: "show all posts" link in profile is wrong
vas3k Oct 30, 2021
c8f4414
feat: remove NLTK dependency + add test docker build step
vas3k Oct 30, 2021
dcaa261
fix #714: add login button to public pages (#763)
MrModest Oct 30, 2021
7cd2c90
Refactor daily and weekly digest renderers
vas3k Nov 1, 2021
87fc1ad
Remove old supervisor config
vas3k Nov 1, 2021
cbdf036
fix: use sum of prices for top badges page
vas3k Nov 1, 2021
fd3a6cc
Add data archives cleanup to crontab
vas3k Nov 1, 2021
6db572d
fix #765: css padding for upvote button
vas3k Nov 1, 2021
4becf03
Upstream
Nov 4, 2021
8b8a2b3
Merge pull request #8 from vas3k/master
glader Nov 4, 2021
195d23f
Makefile
Nov 4, 2021
2c31712
Docker deploy
Nov 4, 2021
49a3b87
Фикс CI
Nov 4, 2021
9c13c06
Сборка из указанного тега
Nov 6, 2021
9690917
Права на крон
Nov 7, 2021
e59fb73
Merge branch 'master' into docker
vas3k Nov 7, 2021
92596a9
Prepare for test deployment
vas3k Nov 7, 2021
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
60 changes: 44 additions & 16 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,55 @@ on:
- master

jobs:
test_docker_build:
name: Test build docker image (remove before merging "feature/docker-deploy")
build:
name: Build image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- run: docker login ghcr.io -u vas3k -p ${{ secrets.TOKEN }}
- run: docker build -t ghcr.io/vas3k/vas3k.club:latest .
- run: docker image push ghcr.io/vas3k/vas3k.club:latest
- run: docker login ghcr.io -u $GITHUB_ACTOR -p ${{ secrets.TOKEN }}
- run: docker build -t ghcr.io/$GITHUB_ACTOR/club:latest -t ghcr.io/$GITHUB_ACTOR/club:$GITHUB_SHA .
- run: docker image push ghcr.io/$GITHUB_ACTOR/club:$GITHUB_SHA
- run: docker image push ghcr.io/$GITHUB_ACTOR/club:latest

build:
deploy:
name: Deploy
runs-on: ubuntu-latest
needs: build
env:
SSH_KEY_PATH: /tmp/ssh_key
steps:
- name: Pull new code and restart server
uses: appleboy/ssh-action@e59c0ee97a7e5240ed9eb489791adbb9c9ac7f6b
- name: Checkout
uses: actions/checkout@v2
- name: Make envfile
run: export | grep "secret_" | sed "s/declare -x secret_//" > .env
env:
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
MEDIA_UPLOAD_URL: "https://i.vas3k.club/upload/"
with:
host: ${{ secrets.PRODUCTION_SSH_HOST }}
username: ${{ secrets.PRODUCTION_SSH_USERNAME }}
key: ${{ secrets.PRODUCTION_SSH_KEY }}
envs: POSTGRES_PASSWORD,MEDIA_UPLOAD_URL
script: cd vas3k.club && git pull && make redeploy
secret_SECRET_KEY: ${{ secrets.SECRET_KEY }}
secret_APP_HOST: ${{ secrets.APP_HOST }}
secret_MEDIA_UPLOAD_URL: ${{ secrets.MEDIA_UPLOAD_URL }}
secret_MEDIA_UPLOAD_CODE: ${{ secrets.MEDIA_UPLOAD_CODE }}
secret_SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
secret_EMAIL_HOST: ${{ secrets.EMAIL_HOST }}
secret_EMAIL_HOST_USER: ${{ secrets.EMAIL_HOST_USER }}
secret_EMAIL_HOST_PASSWORD: ${{ secrets.EMAIL_HOST_PASSWORD }}
secret_TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
secret_TELEGRAM_BOT_URL: ${{ secrets.TELEGRAM_BOT_URL }}
secret_TELEGRAM_ADMIN_CHAT_ID: ${{ secrets.TELEGRAM_ADMIN_CHAT_ID }}
secret_TELEGRAM_CLUB_CHANNEL_URL: ${{ secrets.TELEGRAM_CLUB_CHANNEL_URL }}
secret_TELEGRAM_CLUB_CHANNEL_ID: ${{ secrets.TELEGRAM_CLUB_CHANNEL_ID }}
secret_TELEGRAM_CLUB_CHAT_URL: ${{ secrets.TELEGRAM_CLUB_CHAT_URL }}
secret_TELEGRAM_CLUB_CHAT_ID: ${{ secrets.TELEGRAM_CLUB_CHAT_ID }}
secret_TELEGRAM_ONLINE_CHANNEL_URL: ${{ secrets.TELEGRAM_ONLINE_CHANNEL_URL }}
secret_TELEGRAM_ONLINE_CHANNEL_ID: ${{ secrets.TELEGRAM_ONLINE_CHANNEL_ID }}
secret_STRIPE_ACTIVE: ${{ secrets.STRIPE_ACTIVE }}
secret_STRIPE_API_KEY: ${{ secrets.STRIPE_API_KEY }}
secret_STRIPE_PUBLIC_KEY: ${{ secrets.STRIPE_PUBLIC_KEY }}
secret_STRIPE_WEBHOOK_SECRET: ${{ secrets.STRIPE_WEBHOOK_SECRET }}
secret_PATREON_CLIENT_ID: ${{ secrets.PATREON_CLIENT_ID }}
secret_PATREON_CLIENT_SECRET: ${{ secrets.PATREON_CLIENT_SECRET }}
secret_JWT_PRIVATE_KEY: ${{ secrets.JWT_PRIVATE_KEY }}
secret_WEBHOOK_SECRETS: ${{ secrets.WEBHOOK_SECRETS }}
- run: echo "GITHUB_SHA=$GITHUB_SHA" >> .env
- run: echo "${{ secrets.PRODUCTION_SSH_KEY }}" > ${{ env.SSH_KEY_PATH }} && chmod 600 ${{ env.SSH_KEY_PATH }}
- run: scp -o StrictHostKeyChecking=no -i ${{ env.SSH_KEY_PATH }} .env ${{ secrets.PRODUCTION_SSH_USERNAME }}@${{ secrets.PRODUCTION_SSH_HOST }}:/home/vas3k/vas3k.club/.env
- run: scp -o StrictHostKeyChecking=no -i ${{ env.SSH_KEY_PATH }} docker-compose.production.yml ${{ secrets.PRODUCTION_SSH_USERNAME }}@${{ secrets.PRODUCTION_SSH_HOST }}:/home/vas3k/vas3k.club/docker-compose.production.yml
- run: ssh -i ${{ env.SSH_KEY_PATH }} ${{ secrets.PRODUCTION_SSH_USERNAME }}@${{ secrets.PRODUCTION_SSH_HOST }} "cd /home/vas3k/vas3k.club && docker login ghcr.io -u $GITHUB_ACTOR -p ${{ secrets.TOKEN }} && docker pull ghcr.io/$GITHUB_ACTOR/club:$GITHUB_SHA && docker-compose -f docker-compose.production.yml --env-file=.env up -d club_app queue bot cron && docker image prune --force"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ media/images
media/i

club/.env
.env
db.sqlite3
*.session
venv/
Expand Down
9 changes: 7 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@ RUN apt-get update \
gdal-bin \
libgdal-dev \
make \
npm \
cron \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY . /app
COPY etc/crontab /etc/crontab
RUN chmod 600 /etc/crontab

RUN cd frontend && npm install && npm run build && cd ..

RUN pip3 install pipenv==2021.5.29
RUN sh -c 'if [ "$MODE" = 'production' ]; then pipenv lock --keep-outdated --requirements > requirements.txt; fi'
RUN sh -c 'if [ "$MODE" = 'dev' ]; then pipenv lock --dev --requirements > requirements.txt; fi'
RUN pip3 install -r requirements.txt

RUN sh -c 'if [ -e vas3k_club.env ]; then cp -rf vas3k_club.env /app/club/.env; fi'
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ run-bot: ## Runs telegram bot
docker-run-bot:
python3 bot/main.py

docker-run-cron:
env >> /etc/environment
cron -f -l 2

run-uvicorn: ## Runs uvicorn (ASGI) server in managed mode
pipenv run uvicorn --fd 0 --lifespan off club.asgi:application

Expand All @@ -31,6 +35,7 @@ docker-run-dev: ## Runs dev server in docker

docker-run-production: ## Runs production server in docker
python3 manage.py migrate
cp -r /app/frontend/static /tmp/
gunicorn club.asgi:application -w 7 -k uvicorn.workers.UvicornWorker --bind=0.0.0.0:8814 --capture-output --log-level debug --access-logfile - --error-logfile -

help: ## Display this help
Expand Down
20 changes: 14 additions & 6 deletions docker-compose.production.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
version: "3.7"

services:
club_app: &app
build:
dockerfile: Dockerfile
context: .
image: ghcr.io/vas3k/club:${GITHUB_SHA:-latest}
command: make docker-run-production
container_name: club_app
environment:
Expand All @@ -22,9 +18,11 @@ services:
- EMAIL_HOST
- EMAIL_PORT
- DEFAULT_FROM_EMAIL
env_file:
- .env
restart: always
volumes:
- ./frontend/static:/app/frontend/static
- ./frontend/static:/tmp/static
- ./gdpr/downloads:/app/gdpr/downloads
depends_on:
- postgres
Expand Down Expand Up @@ -53,6 +51,16 @@ services:
ports:
- "8816:8816"

cron:
<<: *app
command: make docker-run-cron
container_name: club_cron
depends_on:
- club_app
- postgres
- redis
ports: []

postgres:
image: postgres:12
container_name: club_postgres
Expand Down
17 changes: 8 additions & 9 deletions etc/crontab
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
30 2 * * * /home/vas3k/backup.sh >> /home/vas3k/backup.log 2>&1
0 1 * * * cd /home/vas3k/vas3k.club && /usr/local/bin/pipenv run python manage.py delete_users >>/home/vas3k/crons.log 2>&1
0 3 * * * cd /home/vas3k/vas3k.club && /usr/local/bin/pipenv run python manage.py renew_subscriptions >>/home/vas3k/crons.log 2>&1
0 9 * * 2-6 cd /home/vas3k/vas3k.club && /usr/local/bin/pipenv run python manage.py send_daily_digest --production true >>/home/vas3k/crons.log 2>&1
0 11 * * 1 cd /home/vas3k/vas3k.club && /usr/local/bin/pipenv run python manage.py send_weekly_digest --production true >>/home/vas3k/crons.log 2>&1
0 5 * * 7 cd /home/vas3k/vas3k.club && /usr/local/bin/pipenv run python manage.py rebuild_search_index >>/home/vas3k/crons.log 2>&1
0 8 * * * cd /home/vas3k/vas3k.club && /usr/local/bin/pipenv run python manage.py replay_stuck_reviews >>/home/vas3k/crons.log 2>&1
0 8 * * * find /home/vas3k/vas3k.club/gdpr/downloads/ -mindepth 1 -mtime +3 -type f -delete >>/home/vas3k/crons.log 2>&1
13 */3 * * * cd /home/vas3k/vas3k.club && /usr/local/bin/pipenv run python manage.py update_hotness >>/home/vas3k/crons.log 2>&1
0 1 * * * root cd /app && python3 manage.py delete_users >/proc/1/fd/1 2>/proc/1/fd/2
0 3 * * * root cd /app && python3 manage.py renew_subscriptions >/proc/1/fd/1 2>/proc/1/fd/2
0 9 * * 2-6 root cd /app && python3 manage.py send_daily_digest --production true >/proc/1/fd/1 2>/proc/1/fd/2
0 11 * * 1 root cd /app && python3 manage.py send_weekly_digest --production true >/proc/1/fd/1 2>/proc/1/fd/2
0 5 * * 7 root cd /app && python3 manage.py rebuild_search_index >/proc/1/fd/1 2>/proc/1/fd/2
0 8 * * * root cd /app && python3 manage.py replay_stuck_reviews >/proc/1/fd/1 2>/proc/1/fd/2
0 8 * * * find /app/gdpr/downloads/ -mindepth 1 -mtime +3 -type f -delete >/proc/1/fd/1 2>/proc/1/fd/2
13 * * * * root cd /app && python3 manage.py update_hotness >/proc/1/fd/1 2>/proc/1/fd/2