Skip to content

Commit

Permalink
Merge pull request #42 from a5chin/feature/docker
Browse files Browse the repository at this point in the history
Refactor Docker
  • Loading branch information
a5chin authored Nov 24, 2024
2 parents 3f7cf77 + 5f21c98 commit d22ab77
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 125 deletions.
28 changes: 5 additions & 23 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
FROM debian:bookworm-slim AS builder
ARG UV_VERSION=0.5.4
ARG DEBIAN_VERSION=bookworm

ENV CARGO_HOME="/opt/.cargo"

SHELL [ "/bin/bash", "-o", "pipefail", "-c" ]
FROM ghcr.io/astral-sh/uv:$UV_VERSION AS uv

WORKDIR /opt

# The installer requires curl (and certificates) to download the release archive
# hadolint ignore=DL3008
RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates curl

# Run uv installer
RUN curl -LsSf https://astral.sh/uv/install.sh | sh


FROM mcr.microsoft.com/vscode/devcontainers/base:bookworm

FROM mcr.microsoft.com/vscode/devcontainers/base:$DEBIAN_VERSION
LABEL maintainer="a5chin <[email protected]>"

ENV CARGO_HOME="/opt/.cargo"
ENV PATH="$CARGO_HOME/bin/:$PATH"
ENV PYTHONUNBUFFERED=True
ENV UV_LINK_MODE=copy

WORKDIR /opt

COPY --from=builder --chown=vscode: $CARGO_HOME $CARGO_HOME
COPY --from=uv --chown=vscode: /uv /uvx /bin/
33 changes: 0 additions & 33 deletions .devcontainer/buildWithRust.Dockerfile

This file was deleted.

32 changes: 14 additions & 18 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
"name": "uv",
"build": {
"context": "..",
"dockerfile": "Dockerfile"
"dockerfile": "Dockerfile",
"args": {
"UV_VERSION": "0.5.4",
"DEBIAN_VERSION": "bookworm"
}
},
"features": {
"ghcr.io/dhoeric/features/hadolint:1": {}
Expand All @@ -11,33 +15,25 @@
"vscode": {
"extensions": [
"charliermarsh.ruff",
"codezombiech.gitignore",
"eamodio.gitlens",
"exiasr.hadolint",
"kevinrose.vsc-python-indent",
"mosapride.zenkaku",
"ms-azuretools.vscode-docker",
"ms-python.python",
"njpwerner.autodocstring",
"oderwat.indent-rainbow",
"pkief.material-icon-theme",
"redhat.vscode-yaml",
"shardulm94.trailing-spaces",
"tamasfe.even-better-toml",
"usernamehw.errorlens",
"yzhang.markdown-all-in-one"
],
"settings": {
"terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/bin/zsh"
}
}
}
"tamasfe.even-better-toml"
]
}
},
"postCreateCommand": "uv python pin $(cat .python-version) && uv sync --dev",
"containerEnv": {
"DISPLAY": "dummy",
"PYTHONUNBUFFERED": "True",
"UV_LINK_MODE": "copy",
"UV_PROJECT_ENVIRONMENT": "/home/vscode/.venv"
},
"postCreateCommand": "uv sync --frozen",
"postStartCommand": "uv run pre-commit install",
"remoteUser": "vscode"
}
35 changes: 0 additions & 35 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,6 @@ jobs:
with:
dockerfile: .devcontainer/Dockerfile

lint-devcontainer-with-rust:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Lint Dockerfile
uses: hadolint/[email protected]
with:
dockerfile: .devcontainer/Dockerfile

build:
runs-on: ubuntu-latest

Expand Down Expand Up @@ -88,26 +76,3 @@ jobs:
tags: latest
cache-from: type=gha
cache-to: type=gha,mode=max

build-devcontainer-with-rust:
runs-on: ubuntu-latest

needs: lint-devcontainer-with-rust
if: ${{ success() }}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: .devcontainer/buildWithRust.Dockerfile
push: false
tags: latest
cache-from: type=gha
cache-to: type=gha,mode=max
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
{
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"python.defaultInterpreterPath": ".venv/bin/python",
"python.defaultInterpreterPath": "/home/vscode/.venv/bin/python",
"terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/bin/zsh"
}
},
"[dockercompose]": {
"editor.autoIndent": "advanced",
"editor.defaultFormatter": "redhat.vscode-yaml",
Expand Down
27 changes: 12 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
ARG DEBIAN_VERSION=bookworm
ARG UV_VERSION=0.5.4
ARG VARIANT=3.12

FROM python:${VARIANT} AS builder

ENV PYTHONDONTWRITEBYTECODE=True
ENV UV_LINK_MODE=copy

WORKDIR /opt
FROM ghcr.io/astral-sh/uv:$UV_VERSION AS uv

COPY pyproject.toml uv.lock ./

# hadolint ignore=DL3013,DL3042
RUN pip install --upgrade pip && \
pip install uv && \
uv sync --frozen

FROM python:$VARIANT-slim-$DEBIAN_VERSION
LABEL maintainer="a5chin <[email protected]>"

FROM python:${VARIANT}-slim
ENV PYTHONDONTWRITEBYTECODE=True
ENV PYTHONUNBUFFERED=True
ENV UV_LINK_MODE=copy

LABEL maintainer="a5chin <[email protected]>"
WORKDIR /app

COPY --from=builder /usr/local/lib/python*/site-packages /usr/local/lib/python*/site-packages
COPY --from=uv /uv /uvx /bin/
COPY pyproject.toml uv.lock ./

ENV PYTHONUNBUFFERED=True
RUN uv sync --frozen --no-install-project

0 comments on commit d22ab77

Please sign in to comment.