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

Deployment #74

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,16 @@ COPY --from=web_stage --link /srv/app/dist public/
COPY --link docker/caddy/Caddyfile /etc/caddy/Caddyfile


FROM python:3.10-alpine as app_scraper

WORKDIR /srv/app
COPY --link ./scraper .

RUN pip install -r requirements.txt

ADD docker/cron/run-scraper.sh /opt/run-scraper.sh
ADD docker/cron/crontab /etc/cron.d/cron-file
RUN chmod 0644 /etc/cron.d/cron-file
RUN crontab /etc/cron.d/cron-file

CMD ["crond", "-f"]
25 changes: 23 additions & 2 deletions api/cmd/create_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ func CreateUser() {
return
}

fmt.Printf("Username: %s, Password: %s\n", username, password)
role, err := getRole()
if err != nil {
fmt.Print("Something went wrong :(")
return
}

user := models.User{
Id: primitive.NewObjectID(),
Role: role,
Name: username,
Password: password,
}
Expand All @@ -32,7 +37,23 @@ func CreateUser() {
return
}

fmt.Printf("User %s was succesfully created \n", username)
fmt.Printf("User %s with Role %s was succesfully created \n", username, role)
}

func getRole() (models.Role, error) {
reader := bufio.NewReader(os.Stdin)
fmt.Println("[0] RoleUser, [1] RoleAdmin")
fmt.Print("Choose Role: ")
roleIndex, err := reader.ReadString('\n')
if err != nil {
return "", err
}

if strings.TrimSpace(roleIndex) == "1" {
return models.RoleAdmin, nil
}

return models.RoleUser, nil
}

// https://stackoverflow.com/a/32768479/14280311 thank you! 🙏
Expand Down
8 changes: 8 additions & 0 deletions docker-compose.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ services:
environment:
SERVER_NAME: ${SERVER_NAME:-localhost}

scraper:
restart: unless-stopped
build:
context: .
target: app_scraper
depends_on:
- api

volumes:
db-data:
db-log:
Expand Down
1 change: 1 addition & 0 deletions docker/cron/crontab
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20 4 * * * /opt/run-scraper.sh
2 changes: 2 additions & 0 deletions docker/cron/run-scraper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
python /srv/app/main.py lmu-cs -d --debug