diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index 96ef862..0000000 --- a/.dockerignore +++ /dev/null @@ -1,2 +0,0 @@ -target/ -.idea/ diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b21568c..bf9eec6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -63,7 +63,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - run: docker build --tag "pod-graceful-drain:latest" . + - run: | + docker build --file docker/build.Dockerfile \ + --tag "pod-graceful-drain:latest" \ + . - run: docker image save --output pod-graceful-drain.tar pod-graceful-drain - uses: actions/upload-artifact@v4 with: diff --git a/charts/pod-graceful-drain/templates/deployment.yaml b/charts/pod-graceful-drain/templates/deployment.yaml index 0164c0c..7893aa3 100644 --- a/charts/pod-graceful-drain/templates/deployment.yaml +++ b/charts/pod-graceful-drain/templates/deployment.yaml @@ -46,7 +46,7 @@ spec: {{- end }} env: - name: RUST_LOG - value: {{ .Values.logLevel }} + value: {{ .Values.logLevel | quote }} readinessProbe: httpGet: path: "/healthz" diff --git a/Dockerfile b/docker/build.Dockerfile similarity index 71% rename from Dockerfile rename to docker/build.Dockerfile index b3d1eb6..1887c7a 100644 --- a/Dockerfile +++ b/docker/build.Dockerfile @@ -1,11 +1,7 @@ -FROM rust:1.79-slim-bookworm as fetch +FROM rust:1.79-slim-bookworm as builder +RUN apt-get update && apt-get install -y git RUN mkdir /src WORKDIR /src -COPY ./Cargo.* /src/ -RUN cargo fetch --verbose - -FROM fetch as builder -RUN apt-get update && apt-get install -y git COPY . /src/ RUN cargo install --path . diff --git a/docker/build.Dockerfile.dockerignore b/docker/build.Dockerfile.dockerignore new file mode 100644 index 0000000..9fea67c --- /dev/null +++ b/docker/build.Dockerfile.dockerignore @@ -0,0 +1,16 @@ +/.github/ +/charts/ +/tests/ +/.gitignore +/LICENSE +/README.md +/.python-version +/pyproject.toml +/requirements.lock +/requirements-dev.lock +/skaffold.yaml + +/target/ +/.venv/ + +/.idea/ diff --git a/docker/skaffold.Dockerfile b/docker/skaffold.Dockerfile new file mode 100644 index 0000000..b2970dd --- /dev/null +++ b/docker/skaffold.Dockerfile @@ -0,0 +1,26 @@ +FROM rust:1.79-slim-bookworm AS cache + +# prepare git cli +RUN apt-get update && apt-get install -y git + +# create /src dir +RUN mkdir /src +WORKDIR /src + +# warm-up dependencies build cache +COPY ./Cargo.* /src/ +COPY build.rs /src/ +RUN mkdir src && \ + echo 'fn main() { println!("Hello, world!"); }' > src/main.rs && \ + cargo build && \ + rm -rf src + +FROM cache AS build + +COPY . /src/ +RUN cargo build + +FROM debian:bookworm-slim +WORKDIR /app +COPY --from=build /src/target/debug/pod-graceful-drain /app/pod-graceful-drain +ENTRYPOINT ["/app/pod-graceful-drain"] diff --git a/docker/skaffold.Dockerfile.dockerignore b/docker/skaffold.Dockerfile.dockerignore new file mode 100644 index 0000000..59b7a58 --- /dev/null +++ b/docker/skaffold.Dockerfile.dockerignore @@ -0,0 +1,17 @@ +/.git/ +/.github/ +/charts/ +/tests/ +/.gitignore +/LICENSE +/README.md +/.python-version +/pyproject.toml +/requirements.lock +/requirements-dev.lock +/skaffold.yaml + +/.venv/ +/target/ + +/.idea/ diff --git a/skaffold.yaml b/skaffold.yaml new file mode 100644 index 0000000..3be6644 --- /dev/null +++ b/skaffold.yaml @@ -0,0 +1,35 @@ +# skaffold is just to help tighten the local development/test loop +apiVersion: skaffold/v4beta11 +kind: Config +metadata: + name: pod-graceful-drain +build: + artifacts: + - image: ghcr.io/foriequal0/pod-graceful-drain + docker: + dockerfile: docker/skaffold.Dockerfile + context: . + local: + push: false + useBuildkit: true + concurrency: 0 +deploy: + helm: + releases: + - name: pod-graceful-drain + chartPath: charts/pod-graceful-drain + valuesFiles: + - charts/pod-graceful-drain/values.yaml + setValues: + experimentalGeneralIngress: true + # Skaffold sends this parameter to Helm as a command line parameter + # '--set=logLevel=info,pod_graceful_drain=trace'. If we omit the backslash, + # Helm interprets a comma in the parameter as a delimiter for key=value pair, + # and it tries to set non-existent 'pod_graceful_drain' value to 'trace'. + # This escaping backslash is why I RIIR'd everything. + # Whenever I see Google-related products, I see this kind of practice. + # They implement some features in seemingly-unharmful broken ways because it is quick and simple. + # When they find features are broken, they don't fix it for compatibility reasons. + # Instead, they cover them up with still-broken ad-hoc mechanisms in obscure, undocumented ways. + # And they leak throughout their entire layers of abstractions like this. + logLevel: "info\\,pod_graceful_drain=trace"