-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: split pre-commit tool image from devcontainer
- Loading branch information
Showing
7 changed files
with
68 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# hadolint ignore=DL3006 | ||
FROM common_context AS common_context | ||
|
||
# hadolint ignore=DL3006 | ||
FROM base_context | ||
ARG USER=root | ||
USER $USER | ||
ARG DEVCONTAINER_PRE_COMMIT_IMAGE | ||
# Burn the pre-commit image ref into the image for use in the caller script | ||
ENV DEVCONTAINER_PRE_COMMIT_IMAGE=$DEVCONTAINER_PRE_COMMIT_IMAGE | ||
# Apply pre-commit caller executable | ||
COPY pre-commit/pre-commit /usr/local/bin | ||
COPY --from=common_context on_create_command /opt/devcontainers/on_create_command | ||
# Include pre-commit initialization in config for devcontainers onCreateCommand | ||
COPY pre-commit/on_create_command /opt/devcontainers/on_create_command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,40 @@ | ||
variable "USER" { | ||
default = "root" | ||
} | ||
variable "DEVCONTAINER_REGISTRY" { | ||
default = "" | ||
} | ||
variable "DEVCONTAINER_IMAGE" { | ||
default = "" | ||
} | ||
variable "PRE_COMMIT_TOOL_IMAGE" { | ||
default = "type=registry,name=${DEVCONTAINER_REGISTRY}:${DEVCONTAINER_IMAGE}-pre-commit" | ||
} | ||
|
||
target "pre-commit" { | ||
target "pre-commit-base" { | ||
dockerfile-inline = "FROM base_context" | ||
} | ||
|
||
target "pre-commit-tool-image" { | ||
dockerfile = "pre-commit/Dockerfile" | ||
contexts = { | ||
local_context = BAKE_CMD_CONTEXT | ||
base_context = "target:pre-commit-base" | ||
} | ||
output = ["${PRE_COMMIT_TOOL_IMAGE}"] | ||
} | ||
|
||
target "pre-commit" { | ||
dockerfile = "pre-commit/caller.Dockerfile" | ||
contexts = { | ||
local_context = BAKE_CMD_CONTEXT | ||
common_context = "common" | ||
base_context = "target:pre-commit-base" | ||
// Tool context is unused; referenced only to establish it as a dep | ||
tool_context = "target:pre-commit-tool-image" | ||
} | ||
args = { | ||
USER = "${USER}" | ||
DEVCONTAINER_PRE_COMMIT_IMAGE = "${PRE_COMMIT_TOOL_IMAGE}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
#!/bin/bash | ||
|
||
PATH="$DEVCONTAINER_PRE_COMMIT/venv/bin:$PATH" "$DEVCONTAINER_PRE_COMMIT/venv/bin/pre-commit" "$@" | ||
set -e | ||
|
||
export PRE_COMMIT_ARGS=($@) | ||
docker run \ | ||
--rm \ | ||
-it \ | ||
--name pre-commit \ | ||
--user root \ | ||
--entrypoint bash \ | ||
-v "$(pwd):$(pwd)" \ | ||
-w "$(pwd)" \ | ||
-e DEVCONTAINER_PRE_COMMIT \ | ||
-e PRE_COMMIT_ARGS \ | ||
"$DEVCONTAINER_PRE_COMMIT_IMAGE" \ | ||
-c 'git config --global --add safe.directory "$(pwd)" && PATH="$DEVCONTAINER_PRE_COMMIT/venv/bin:$PATH" "$DEVCONTAINER_PRE_COMMIT/venv/bin/pre-commit" "${PRE_COMMIT_ARGS[@]}"' | ||
|
||
sudo chown -R $USER:$USER $(pwd) |