Skip to content

Commit

Permalink
Merge pull request #24 from a-luna:fix-gh-action-deploy_attempt-10
Browse files Browse the repository at this point in the history
Refactor RedisClient password_discreet method
  • Loading branch information
a-luna authored Jan 6, 2024
2 parents cc47a4c + 99e804e commit c0aa9cc
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 13 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/deploy_unicode_api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ jobs:
files: ./docker-bake.hcl
targets: unicode-api
push: true
set: unicode-api.args.REDIS_PW=${{ secrets.REDIS_PW }}
set: |
unicode-api.args.REDIS_PW=${{ secrets.REDIS_PW }}
unicode-api.args.TEST1=BAKE_SET1
- name: Deploy unicode-api docker image to dokku
uses: dokku/github-action@master
with:
Expand Down
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ ARG RATE_LIMIT_PER_PERIOD
ARG RATE_LIMIT_PERIOD_SECONDS
ARG RATE_LIMIT_BURST
ARG TEST_HEADER
ARG TEST1
ARG TEST2

ENV ENV=${ENV}
ENV UNICODE_VERSION=${UNICODE_VERSION}
Expand All @@ -21,12 +23,19 @@ ENV RATE_LIMIT_PER_PERIOD=${RATE_LIMIT_PER_PERIOD}
ENV RATE_LIMIT_PERIOD_SECONDS=${RATE_LIMIT_PERIOD_SECONDS}
ENV RATE_LIMIT_BURST=${RATE_LIMIT_BURST}
ENV TEST_HEADER=${TEST_HEADER}
ENV TEST1=${TEST1}
ENV TEST2=${TEST2}

WORKDIR /code
RUN pip install -U pip setuptools wheel
COPY ./requirements.txt /code/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
EXPOSE 80
COPY ./app /code/app

RUN echo REDIS_PW: $REDIS_PW
RUN echo TEST1: $TEST1
RUN echo TEST2: $TEST2

RUN PYTHONPATH=/code/. python /code/./app/data/scripts/get_prod_data.py
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
2 changes: 1 addition & 1 deletion app/core/rate_limit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import re
from dataclasses import dataclass, field
from dataclasses import dataclass
from datetime import timedelta

from fastapi import Request
Expand Down
8 changes: 7 additions & 1 deletion app/core/redis_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ def __init__(self):

@property
def password_discreet(self) -> str:
return f'{"*" * self.redis_pw[:-4]}{self.redis_pw[-4:]}' if self.redis_pw else ""
if not self.redis_pw:
return ""
return (
f'{"*" * len(self.redis_pw[:-4])}{self.redis_pw[-4:]}'
if len(self.redis_pw) > 4
else "*" * len(self.redis_pw)
)

@property
def redis_url(self) -> str:
Expand Down
30 changes: 20 additions & 10 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,29 @@ variable "REDIS_PW" {
default = ""
}

variable "TEST1" {
default = "NOT_SECRET1"
}

variable "TEST2" {
default = "NOT_SECRET2"
}

target "unicode-api" {
dockerfile = "./Dockerfile"
tags = ["ghcr.io/a-luna/unicode-api:${GITHUB_SHA}"]
args = {
ENV = "PROD"
UNICODE_VERSION = "15.1.0"
REDIS_HOST = "dokku-redis-vig-cache"
REDIS_PORT = "6379"
REDIS_DB = "1"
REDIS_PW = "${REDIS_PW}"
RATE_LIMIT_PER_PERIOD = "50"
RATE_LIMIT_PERIOD_SECONDS = "60"
RATE_LIMIT_BURST = "10"
TEST_HEADER = "X-UnicodeAPI-Test"
ENV="PROD"
UNICODE_VERSION="14.0.0"
REDIS_HOST="dokku-redis-vig-cache"
REDIS_PORT="6379"
REDIS_DB="1"
REDIS_PW="${REDIS_PW}"
RATE_LIMIT_PER_PERIOD="45"
RATE_LIMIT_PERIOD_SECONDS="55"
RATE_LIMIT_BURST="5"
TEST_HEADER="X-UnicodeAPI-Test"
TEST1="${TEST1}"
TEST2="${TEST2}"
}
}

0 comments on commit c0aa9cc

Please sign in to comment.