-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new ud to perform an op[timized deep clone
- Loading branch information
Showing
5 changed files
with
127 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
VERSION --arg-scope-and-set 0.7 | ||
|
||
# DEEP_CLONE deep clones the provided git repository | ||
DEEP_CLONE: | ||
COMMAND | ||
ARG USE_GIT_ENV="false" | ||
IF [ $USE_GIT_ENV = "true" ] | ||
FROM alpine/git:v2.40.1 | ||
END | ||
DO ../ssh+ADD_KNOWN_HOSTS | ||
ARG --required GIT_URL | ||
ARG DEST_DIR | ||
LET dest_dir=$DEST_DIR | ||
IF [ -z $dest_dir ] | ||
SET dest_dir=$(basename ${GIT_URL%.git}) | ||
END | ||
GIT CLONE $GIT_URL $dest_dir | ||
WORKDIR $dest_dir | ||
RUN git remote set-url origin $GIT_URL | ||
ARG git_hash=$(git rev-parse HEAD) | ||
ARG SECRET_PATH | ||
IF [ -z $SECRET_PATH ] | ||
RUN echo secrets path is z | ||
RUN --ssh git fetch --unshallow | ||
ELSE | ||
RUN echo secrets path is NOT z | ||
RUN --mount=type=secret,id=$SECRET_PATH,mode=0400,target=/root/.ssh/id_rsa \ | ||
git fetch --unshallow | ||
END | ||
|
||
test: | ||
BUILD ./tests+all |
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,48 @@ | ||
VERSION --arg-scope-and-set --pass-args 0.7 | ||
|
||
PROJECT earthly-technologies/core | ||
|
||
all: | ||
BUILD --platform=linux/amd64 --platform=linux/arm64 +test-deep-clone-image \ | ||
--base_image=alpine/git:latest \ | ||
--base_image=alpine:latest \ | ||
--base_image=debian:stable \ | ||
--base_image=debian:stable-slim \ | ||
--base_image=ubuntu:latest \ | ||
--base_image=amazonlinux:1 \ | ||
--base_image=amazonlinux:2 \ | ||
--GIT_URL=https://github.com/earthly/lib.git \ | ||
--GIT_URL=[email protected]:earthly/cloud.git \ | ||
--GIT_URL=[email protected]:earthly/cloud \ | ||
--SECRET_PATH="" \ | ||
--SECRET_PATH="littleredcorvette-id_rsa" \ | ||
--DEST_DIR="" \ | ||
--DEST_DIR="some-other-dir" | ||
|
||
test-deep-clone-image: | ||
ARG --required base_image | ||
ARG TARGETPLATFORM | ||
FROM alpine | ||
IF [ "$base_image" = "amazonlinux:1" ] && [ "$TARGETPLATFORM" = "linux/arm64" ] # no amazonlinux:1 for arm64, skipping | ||
RUN echo skipping $base_image with platform $TARGETPLATFORM | ||
ELSE | ||
FROM "$base_image" | ||
LET use_git_env="true" | ||
IF [ "${base_image%:*}" = "alpine/git" ] | ||
SET use_git_env="false" | ||
RUN apk add git | ||
ELSE IF [ "${base_image%:*}" = "alpine" ] | ||
RUN apk add git | ||
ELSE IF [ "${base_image%:*}" = "debian" ] | ||
RUN apt update && apt install -y git | ||
ELSE IF [ "${base_image%:*}" = "ubuntu" ] | ||
RUN apt-get update && apt-get -y install git | ||
ELSE IF [[ $base_image == amazonlinux* ]] | ||
RUN yum -y install git | ||
END | ||
DO --pass-args ..+DEEP_CLONE --USE_GIT_ENV=$use_git_env | ||
IF [ -n $DEST_DIR ] | ||
WORKDIR $DEST_DIR | ||
END | ||
RUN git checkout main | ||
END |
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,38 @@ | ||
VERSION --pass-args --arg-scope-and-set 0.7 | ||
|
||
all: | ||
BUILD --platform=linux/amd64 --platform=linux/arm64 +test-add-known-hosts-image \ | ||
--base_image=alpine:latest \ | ||
--base_image=debian:stable \ | ||
--base_image=debian:stable-slim \ | ||
--base_image=ubuntu:latest \ | ||
--base_image=amazonlinux:1 \ | ||
--base_image=amazonlinux:2 \ | ||
--target_file=~/to_interpolate/known_hosts \ | ||
--target_file=no_dir_new_known_hosts \ | ||
--target_file=/some/dir/to/file/new_known_hosts \ | ||
--target_file=existing_known_hosts # this will be handled in the test target | ||
|
||
test-add-known-hosts-image: | ||
ARG --required base_image | ||
ARG TARGETPLATFORM | ||
FROM alpine | ||
IF [ "$base_image" = "amazonlinux:1" ] && [ "$TARGETPLATFORM" = "linux/arm64" ] # no amazonlinux:1 for arm64, skipping | ||
RUN echo skipping $base_image with platform $TARGETPLATFORM | ||
ELSE | ||
FROM "$base_image" | ||
IF [ "$base_image" = "amazonlinux:1" ] | ||
RUN yum -y install diffutils.x86_64 | ||
END | ||
COPY ..+known-hosts/known_hosts /tmp/expected-temp | ||
RUN test -s /tmp/expected-temp | ||
ARG target_file | ||
IF [ "$target_file" = "existing_known_hosts" ] | ||
RUN echo some-key >> /tmp/expected | ||
RUN echo some-key >> $target_file | ||
END | ||
RUN cat /tmp/expected-temp >> /tmp/expected | ||
DO --pass-args ..+ADD_KNOWN_HOSTS | ||
LET expanded_target_file="$(eval echo $target_file)" | ||
RUN diff /tmp/expected $(eval echo $expanded_target_file) | ||
END |