diff --git a/Dockerfile b/Dockerfile index 61654ba..7d82a51 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/api/cmd/create_user.go b/api/cmd/create_user.go index 69f0403..0d8836b 100644 --- a/api/cmd/create_user.go +++ b/api/cmd/create_user.go @@ -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, } @@ -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! 🙏 diff --git a/docker-compose.prod.yaml b/docker-compose.prod.yaml index e2ea555..0aed2b3 100644 --- a/docker-compose.prod.yaml +++ b/docker-compose.prod.yaml @@ -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: diff --git a/docker/cron/crontab b/docker/cron/crontab new file mode 100644 index 0000000..b3ff18e --- /dev/null +++ b/docker/cron/crontab @@ -0,0 +1 @@ +20 4 * * * /opt/run-scraper.sh diff --git a/docker/cron/run-scraper.sh b/docker/cron/run-scraper.sh new file mode 100644 index 0000000..369cf4c --- /dev/null +++ b/docker/cron/run-scraper.sh @@ -0,0 +1,2 @@ +#!/bin/sh +python /srv/app/main.py lmu-cs -d --debug