Skip to content

Commit

Permalink
Refactor Dockerfile and linter.py for improved readability and mainta…
Browse files Browse the repository at this point in the history
…inability
  • Loading branch information
ursisterbtw committed Dec 9, 2024
1 parent 27958ec commit 2e8408f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
13 changes: 11 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
FROM mcr.microsoft.com/devcontainers/base:ubuntu

# add healthcheck
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost/ || exit 1

# create non-root user
RUN useradd -m -s /bin/bash devuser
USER devuser

# Set non-interactive mode for APT
ENV DEBIAN_FRONTEND=noninteractive

# Install necessary packages
# trunk-ignore(hadolint/DL3008)
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
curl \
build-essential=12.9ubuntu3 \
curl=7.81.0-1ubuntu1.15 \
git \
libssl-dev \
pkg-config \
Expand Down
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
FROM rust:1.82 AS builder
RUN groupadd -r appuser && useradd -r -g appuser appuser
WORKDIR /usr/src/app
COPY . .
RUN cargo build --release
RUN cargo build --release && \
chown -R appuser:appuser /usr/src/app
USER appuser

FROM ubuntu:22.04
RUN apt-get update && apt-get install -y --no-install-recommends \
libssl3 \
supervisor && \
libssl3=3.0.2-0ubuntu1.15 \
supervisor=4.2.1-2ubuntu4 && \
rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/src/app/target/release/hash_hunter /usr/local/bin/hash_hunter
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
WORKDIR /usr/src/app
RUN mkdir -p /usr/src/app/gen
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD pgrep supervisord || exit 1
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
8 changes: 6 additions & 2 deletions linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def lint_and_uncapitalize_comments(file_path):
if stripped_line.startswith("#"):
# find the comment text after the `#`
comment = stripped_line[1:].lstrip()
# check if it starts with a capital letter
if comment and comment[0].isupper():
# check if it starts with a capital letter, but ignore "SAFETY:" comments
if comment and comment[0].isupper() and not comment.lstrip().startswith("SAFETY:"):
# replace the line with the uncapitalized comment
new_comment = comment[0].lower() + comment[1:]
line = line.replace(comment, new_comment, 1)
Expand All @@ -37,6 +37,10 @@ def lowercase_comment_leading_letter(file_path):

with open(file_path, "w", encoding="utf-8") as file:
for line in lines:
# skip lowercasing if the comment contains "SAFETY:"
if "SAFETY:" in line:
file.write(line)
continue
match = re.match(r"^\s*//+\s*([A-Z])", line)
if match:
line = re.sub(r"^(\s*//+\s*)([A-Z])", lambda m: m.group(1) + m.group(2).lower(), line)
Expand Down

0 comments on commit 2e8408f

Please sign in to comment.