diff --git a/Dockerfile b/Dockerfile index 504f572..369e73d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,14 +9,14 @@ ARG WORKDIR ENV PYTHONUNBUFFERED=1 # Don't create `.pyc` files: ENV PYTHONDONTWRITEBYTECODE=1 -# https://github.com/rust-lang/cargo/issues/2808 +# https://github.com/rust-lang/cargo/issues/2808 ENV CARGO_NET_GIT_FETCH_WITH_CLI=true # For building CFFI / Crypgotraphy (needed on ARM builds): RUN apk add gcc make musl-dev libffi-dev rust cargo git openssl-dev RUN pip install poetry -RUN poetry config virtualenvs.in-project true +RUN poetry config virtualenvs.in-project true WORKDIR ${WORKDIR} @@ -45,7 +45,7 @@ ENV HS_SERVER=http://localhost/ ENV KEY="" # ENV SCRIPT_NAME=/ ENV DOMAIN_NAME=http://localhost -ENV AUTH_TYPE="None" +ENV AUTH_TYPE="" ENV LOG_LEVEL="Info" # BasicAuth variables @@ -61,7 +61,7 @@ ENV OIDC_CLIENT_SECRET=secret ARG GIT_COMMIT_ARG="" ARG GIT_BRANCH_ARG="" ARG APP_VERSION_ARG="" -ARG BUILD_DATE_ARG="NOT SET" +ARG BUILD_DATE_ARG="" ARG HS_VERSION_ARG="" # About section on the Settings page @@ -78,4 +78,4 @@ EXPOSE 5000/tcp ENTRYPOINT ["/app/entrypoint.sh"] # Temporarily reduce to 1 worker -CMD gunicorn -w 1 -b 0.0.0.0:5000 server:app \ No newline at end of file +CMD gunicorn -w 1 -b 0.0.0.0:5000 server:app diff --git a/Jenkinsfile b/Jenkinsfile index a4c8aa5..1b080d5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -26,7 +26,7 @@ pipeline { steps { sh 'printenv' - script { BUILD_DATE = java.time.LocalDate.now() } + script { BUILD_DATE = java.time.DateTimeFormatter.ISO_DATE_TIME.format(java.time.OffsetDateTime.now()) } sh """ # Create the builder: docker buildx create --name $BUILDER_NAME --driver-opt=image=moby/buildkit @@ -62,7 +62,7 @@ pipeline { --label \"GIT_COMMIT=${env.GIT_COMMIT}\" \ --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 \ --push - """ + """ } else { // If I'm just testing, I don't need to build for ARM sh """ docker buildx build . \ @@ -98,10 +98,10 @@ pipeline { } else { sh """ - docker pull git.sysctl.io/albert/headscale-webui:testing - docker pull ghcr.io/ifargle/headscale-webui:testing - docker pull git.sysctl.io/albert/headscale-webui:${env.BRANCH_NAME} - docker pull ghcr.io/ifargle/headscale-webui:${env.BRANCH_NAME} + docker pull git.sysctl.io/albert/headscale-webui:testing + docker pull ghcr.io/ifargle/headscale-webui:testing + docker pull git.sysctl.io/albert/headscale-webui:${env.BRANCH_NAME} + docker pull ghcr.io/ifargle/headscale-webui:${env.BRANCH_NAME} """ } } diff --git a/config.py b/config.py index 31ad541..cb2bc0f 100644 --- a/config.py +++ b/config.py @@ -61,8 +61,12 @@ class BasicAuthConfig(BaseSettings): Used only if "AUTH_TYPE" environment variable is set to "basic". """ - username: str = Field(env="BASIC_AUTH_USER", description="Username for basic auth.") - password: str = Field(env="BASIC_AUTH_PASS", description="Password for basic auth.") + username: str = Field( + "headscale", env="BASIC_AUTH_USER", description="Username for basic auth." + ) + password: str = Field( + "headscale", env="BASIC_AUTH_PASS", description="Password for basic auth." + ) class AuthType(StrEnum): @@ -156,7 +160,7 @@ class InitCheckError(RuntimeError): " %s with type %s: %s", field.field_info.extra["env"], field.type_.__name__, - sub_pydantic_error["type"], + sub_pydantic_error["msg"], ) new_error.append_error( @@ -317,8 +321,8 @@ class Config(BaseSettings): env="APP_VERSION", description="Application version. Should be set by Docker.", ) - build_date: str = Field( - default_factory=str(datetime.now), + build_date: datetime = Field( + default_factory=datetime.now, env="BUILD_DATE", description="Application build date. Should be set by Docker.", ) @@ -383,6 +387,15 @@ class Config(BaseSettings): description="Application data path.", ) + @validator("auth_type", pre=True) + @classmethod + def validate_auth_type(cls, value: Any): + """Validate AUTH_TYPE so that it accepts more valid values.""" + value = str(value).lower() + if value == "": + return AuthType.BASIC + return AuthType(value) + @validator("log_level_name") @classmethod def validate_log_level_name(cls, value: Any): @@ -409,6 +422,23 @@ class Config(BaseSettings): except ZoneInfoNotFoundError as error: raise ValueError(f"Timezone {value} is invalid: {error}") from error + @validator("build_date", pre=True) + @classmethod + def validate_build_date(cls, value: Any): + """Validate build date and accept more values.""" + if isinstance(value, datetime): + return value + assert isinstance(value, str), "BUILD_DATE needs to be a string." + if value == "": + return datetime.now() + try: + return datetime.fromisoformat(value) + except ValueError as error: + current_app.logger.warning( + "BUILD_DATE in wrong format. Expected ISO format. Error: %s", str(error) + ) + return datetime.now() + @validator("hs_config_path", pre=True) @classmethod def validate_hs_config_path(cls, value: Any):