Skip to content

Commit

Permalink
Add github action & update some settings
Browse files Browse the repository at this point in the history
  • Loading branch information
邱宇軒Yuh Suan Chiu committed Feb 10, 2024
1 parent c1bfcf6 commit 2f942ec
Show file tree
Hide file tree
Showing 35 changed files with 165 additions and 622 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/deploy-docker-gce
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Deploy to Google Compute Engine

on:
push:
branches:
- dev # Replace with your branch

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Build and push Docker image
uses: actions/checkout@v3
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/snap_up_thsr:latest

- name: Setup Google Cloud SDK
uses: google-github-actions/setup-gcloud@master
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
export_default_credentials: true

- name: Deploy to GCE
run: |
gcloud compute ssh user@instance -- "cd snap_up_thsr && \
git pull && \
docker run --network=${{ secrets.LIVE_NETWORK }} \
-p 8080:8000 \
-e REDIS_HOST=${{ secrets.REDIS_HOST }} \
-e DB_HOST=${{ secrets.DB_HOST }} \
-e DB_USER=${{ secrets.DB_USER }} \
-e DB_PASSWORD=${{ secrets.DB_PASSWORD }} \
-e DB_NAME=${{ secrets.DB_NAME }} \
-d \
--restart=always \
--name snap_up_thsr \
${{ secrets.DOCKER_HUB_USERNAME }}/snap_up_thsr:latest
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ __pycache__/
# projects
requirements/dev.txt
*.log
recognize_img.py

.github/
/src/static
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ RUN apt update && \
apt install -y libpq5 procps && \
pip install -r /requirements/live.txt

CMD ["gunicorn", "--timeout=300", "--workers=2", "--threads=8", "--keep-alive=60", "src.wsgi:application"]
CMD ["gunicorn", "--timeout=300", "--workers=2", "--threads=8", "--keep-alive=60", "src.wsgi:application"]
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ services:
image: redis:alpine
ports:
- "8684:6379"

db:
image: postgres:latest
restart: always
Expand All @@ -26,6 +27,6 @@ services:
- ./requirements:/requirements
ports:
- "8686:8000"
command: bash -c "pip freeze > /requirements/live.txt && gunicorn --timeout=300 --workers=2 --threads=8 --keep-alive=60 src.wsgi:application"
command: bash -c "pip freeze > /requirements/live.txt && tail -f /dev/null"
environment:
DEPLOY: dev
1 change: 1 addition & 0 deletions requirements/live.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ coloredlogs==15.0.1
ddddocr==1.4.11
Django==4.2
flatbuffers==23.5.26
gunicorn==21.2.0
humanfriendly==10.0
idna==3.6
mpmath==1.3.0
Expand Down
5 changes: 4 additions & 1 deletion requirements/local.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ redis
phonenumbers
requests
beautifulsoup4
ddddocr
ddddocr

# live
gunicorn
95 changes: 21 additions & 74 deletions src/booking/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2 on 2023-10-07 10:49
# Generated by Django 4.2 on 2024-02-10 17:32

from django.db import migrations, models

Expand All @@ -11,67 +11,30 @@ class Migration(migrations.Migration):
]

operations = [
migrations.CreateModel(
name='BookingLog',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('booking_request_id', models.PositiveBigIntegerField()),
('status', models.SmallIntegerField()),
('err_msg', models.TextField()),
('ticket_id', models.CharField(max_length=10)),
],
),
migrations.CreateModel(
name='BookingQueue',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('booking_request_id', models.PositiveBigIntegerField()),
('booking_date', models.DateField()),
('retry_times', models.PositiveSmallIntegerField()),
('max_retry_times', models.PositiveSmallIntegerField()),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='BookingRequest',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('user_email', models.EmailField(max_length=254)),
('status', models.PositiveSmallIntegerField(choices=[(0, 'Not Yet'), (1, 'Pending'), (2, 'Processing'), (3, 'Completed'), (-1, 'Expired'), (-2, 'Deleted')], default=1)),
('train_id', models.CharField(blank=True, max_length=10)),
('depart_station', models.PositiveSmallIntegerField(choices=[(1, '南港'), (2, '台北'), (3, '板橋'), (4, '桃園'), (5, '新竹'), (6, '苗栗'), (7, '台中'), (8, '彰化'), (9, '雲林'), (10, '嘉義'), (11, '台南'), (12, '左營')], default=1)),
('dest_station', models.PositiveSmallIntegerField(choices=[(1, '南港'), (2, '台北'), (3, '板橋'), (4, '桃園'), (5, '新竹'), (6, '苗栗'), (7, '台中'), (8, '彰化'), (9, '雲林'), (10, '嘉義'), (11, '台南'), (12, '左營')], default=12)),
('type_of_trip', models.PositiveSmallIntegerField(choices=[(0, 'One Way'), (1, 'Round Trip')], default=0)),
('booking_method', models.PositiveSmallIntegerField(choices=[(0, 'radio31'), (1, 'radio33')], default=0)),
('booking_method', models.PositiveSmallIntegerField(choices=[(0, 'Time'), (1, 'Train No')], default=0)),
('seat_prefer', models.PositiveSmallIntegerField(choices=[(0, 'No Prefer'), (1, 'Prefer Window'), (2, 'Prefer Aisle')], default=0)),
('adult_num', models.PositiveSmallIntegerField(choices=[(0, 'Zero'), (1, 'One'), (2, 'Two'), (3, 'Three'), (4, 'Four'), (5, 'Five'), (6, 'Six'), (7, 'Seven'), (8, 'Eight'), (9, 'Nine'), (10, 'Ten')], default=1)),
('child_num', models.PositiveSmallIntegerField(choices=[(0, 'Zero'), (1, 'One'), (2, 'Two'), (3, 'Three'), (4, 'Four'), (5, 'Five'), (6, 'Six'), (7, 'Seven'), (8, 'Eight'), (9, 'Nine'), (10, 'Ten')], default=0)),
('disabled_num', models.PositiveSmallIntegerField(choices=[(0, 'Zero'), (1, 'One'), (2, 'Two'), (3, 'Three'), (4, 'Four'), (5, 'Five'), (6, 'Six'), (7, 'Seven'), (8, 'Eight'), (9, 'Nine'), (10, 'Ten')], default=0)),
('elder_num', models.PositiveSmallIntegerField(choices=[(0, 'Zero'), (1, 'One'), (2, 'Two'), (3, 'Three'), (4, 'Four'), (5, 'Five'), (6, 'Six'), (7, 'Seven'), (8, 'Eight'), (9, 'Nine'), (10, 'Ten')], default=0)),
('college_num', models.PositiveSmallIntegerField(choices=[(0, 'Zero'), (1, 'One'), (2, 'Two'), (3, 'Three'), (4, 'Four'), (5, 'Five'), (6, 'Six'), (7, 'Seven'), (8, 'Eight'), (9, 'Nine'), (10, 'Ten')], default=0)),
('depart_date', models.DateField(blank=True)),
('adult_num', models.PositiveSmallIntegerField(choices=[(0, '0'), (1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, '5'), (6, '6'), (7, '7'), (8, '8'), (9, '9'), (10, '10')], default=1)),
('child_num', models.PositiveSmallIntegerField(choices=[(0, '0'), (1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, '5'), (6, '6'), (7, '7'), (8, '8'), (9, '9'), (10, '10')], default=0)),
('disabled_num', models.PositiveSmallIntegerField(choices=[(0, '0'), (1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, '5'), (6, '6'), (7, '7'), (8, '8'), (9, '9'), (10, '10')], default=0)),
('elder_num', models.PositiveSmallIntegerField(choices=[(0, '0'), (1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, '5'), (6, '6'), (7, '7'), (8, '8'), (9, '9'), (10, '10')], default=0)),
('college_num', models.PositiveSmallIntegerField(choices=[(0, '0'), (1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, '5'), (6, '6'), (7, '7'), (8, '8'), (9, '9'), (10, '10')], default=0)),
('depart_date', models.DateField()),
('earliest_depart_time', models.CharField(blank=True, choices=[('', ''), ('500A', '05:00'), ('530A', '05:30'), ('600A', '06:00'), ('630A', '06:30'), ('700A', '07:00'), ('730A', '07:30'), ('800A', '08:00'), ('830A', '08:30'), ('900A', '09:00'), ('930A', '09:30'), ('1000A', '10:00'), ('1030A', '10:30'), ('1100A', '11:00'), ('1130A', '11:30'), ('1200N', '12:00'), ('1230P', '12:30'), ('100P', '13:00'), ('130P', '13:30'), ('200P', '14:00'), ('230P', '14:30'), ('300P', '15:00'), ('330P', '15:30'), ('400P', '16:00'), ('430P', '16:30'), ('500P', '17:00'), ('530P', '17:30'), ('600P', '18:00'), ('630P', '18:30'), ('700P', '19:00'), ('730P', '19:30'), ('800P', '20:00'), ('830P', '20:30'), ('900P', '21:00'), ('930P', '21:30'), ('1000P', '22:00'), ('1030P', '22:30'), ('1100P', '23:00'), ('1130P', '23:30'), ('1201A', '23:59')], default='', max_length=10)),
('latest_arrival_time', models.CharField(blank=True, choices=[('', ''), ('500A', '05:00'), ('530A', '05:30'), ('600A', '06:00'), ('630A', '06:30'), ('700A', '07:00'), ('730A', '07:30'), ('800A', '08:00'), ('830A', '08:30'), ('900A', '09:00'), ('930A', '09:30'), ('1000A', '10:00'), ('1030A', '10:30'), ('1100A', '11:00'), ('1130A', '11:30'), ('1200N', '12:00'), ('1230P', '12:30'), ('100P', '13:00'), ('130P', '13:30'), ('200P', '14:00'), ('230P', '14:30'), ('300P', '15:00'), ('330P', '15:30'), ('400P', '16:00'), ('430P', '16:30'), ('500P', '17:00'), ('530P', '17:30'), ('600P', '18:00'), ('630P', '18:30'), ('700P', '19:00'), ('730P', '19:30'), ('800P', '20:00'), ('830P', '20:30'), ('900P', '21:00'), ('930P', '21:30'), ('1000P', '22:00'), ('1030P', '22:30'), ('1100P', '23:00'), ('1130P', '23:30'), ('1201A', '23:59')], default='1201A', max_length=10)),
('train_id', models.CharField(blank=True, max_length=10)),
('deleted_at', models.DateTimeField(blank=True)),
],
),
migrations.CreateModel(
name='BookingResult',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('user_email', models.EmailField(max_length=254)),
('booking_request_id', models.PositiveBigIntegerField()),
('status', models.PositiveSmallIntegerField(choices=[(1, 'Success'), (-1, 'Fail')])),
('thsr_ticket_id', models.PositiveBigIntegerField()),
('passenger_ids', models.JSONField(blank=True, default=list, null=True)),
('deleted_at', models.DateTimeField(blank=True, null=True)),
('error_msg', models.CharField(blank=True, max_length=255)),
],
),
migrations.CreateModel(
Expand All @@ -81,34 +44,18 @@ class Migration(migrations.Migration):
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('ticket_id', models.CharField(blank=True, max_length=10)),
('total_price', models.CharField(blank=True, max_length=10)),
('payment_deadline', models.CharField(blank=True, max_length=10)),
('depart_time', models.DateTimeField(blank=True)),
('arrival_time', models.DateTimeField(blank=True)),
('depart_station', models.CharField(blank=True, max_length=10)),
('arrival_station', models.CharField(blank=True, max_length=10)),
('train_id', models.CharField(blank=True, max_length=10)),
('seat_num', models.CharField(blank=True, max_length=50)),
('date', models.CharField(blank=True, max_length=10)),
('depart_time', models.CharField(blank=True, max_length=255)),
('arrival_time', models.CharField(blank=True, max_length=255)),
('depart_station', models.PositiveSmallIntegerField(choices=[(1, '南港'), (2, '台北'), (3, '板橋'), (4, '桃園'), (5, '新竹'), (6, '苗栗'), (7, '台中'), (8, '彰化'), (9, '雲林'), (10, '嘉義'), (11, '台南'), (12, '左營')])),
('arrival_station', models.PositiveSmallIntegerField(choices=[(1, '南港'), (2, '台北'), (3, '板橋'), (4, '桃園'), (5, '新竹'), (6, '苗栗'), (7, '台中'), (8, '彰化'), (9, '雲林'), (10, '嘉義'), (11, '台南'), (12, '左營')])),
],
options={
'abstract': False,
},
),
migrations.AddIndex(
model_name='bookingresult',
index=models.Index(fields=['user_email'], name='booking_boo_user_em_08d164_idx'),
),
migrations.AddIndex(
model_name='bookingresult',
index=models.Index(fields=['booking_request_id'], name='booking_boo_booking_03208c_idx'),
),
migrations.AddIndex(
model_name='bookingresult',
index=models.Index(fields=['thsr_ticket_id'], name='booking_boo_thsr_ti_915693_idx'),
),
migrations.AddIndex(
model_name='bookingrequest',
index=models.Index(fields=['user_email'], name='booking_boo_user_em_d76ad1_idx'),
),
migrations.AddIndex(
model_name='bookinglog',
index=models.Index(fields=['booking_request_id'], name='booking_boo_booking_3e6357_idx'),
),
]

This file was deleted.

37 changes: 37 additions & 0 deletions src/booking/migrations/0002_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Generated by Django 4.2 on 2024-02-10 17:32

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('booking', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='thsrticket',
name='user',
field=models.ForeignKey(db_constraint=False, on_delete=django.db.models.deletion.DO_NOTHING, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='bookingrequest',
name='thsr_ticket',
field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='booking.thsrticket', verbose_name='THSR Ticket ID'),
),
migrations.AddField(
model_name='bookingrequest',
name='user',
field=models.ForeignKey(db_constraint=False, on_delete=django.db.models.deletion.DO_NOTHING, to=settings.AUTH_USER_MODEL),
),
migrations.AddIndex(
model_name='bookingrequest',
index=models.Index(fields=['status', '-depart_date'], name='booking_boo_status_9e3d6f_idx'),
),
]

This file was deleted.

This file was deleted.

Loading

0 comments on commit 2f942ec

Please sign in to comment.