-
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.
- Loading branch information
Showing
5 changed files
with
56 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
target | ||
Earthfile |
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 |
---|---|---|
@@ -1,97 +1,66 @@ | ||
VERSION --global-cache 0.7 | ||
IMPORT github.com/earthly/lib/rust AS rust | ||
|
||
rust: | ||
FROM rust:alpine | ||
RUN apk add --no-cache musl-dev findutils | ||
ARG --global CROSS_VERSION=0.2.5 | ||
|
||
cross-deps: | ||
ARG NATIVEPLATFORM | ||
FROM --platform=$NATIVEPLATFORM rust:slim | ||
RUN apt-get update \ | ||
&& apt-get install -y docker.io jq wget \ | ||
&& apt-get clean | ||
WORKDIR /app | ||
DO rust+INIT --keep_fingerprints=true | ||
# DO rust+CARGO --args="install cross@${CROSS_VERSION}" | ||
RUN wget -O- "https://github.com/cross-rs/cross/releases/download/v${CROSS_VERSION}/cross-x86_64-unknown-linux-musl.tar.gz" | tar -xzf - -C /usr/local/bin | ||
DO rust+SET_CACHE_MOUNTS_ENV | ||
|
||
build: | ||
FROM +rust | ||
COPY docker/target.sh / | ||
COPY --keep-ts . ./ | ||
DO rust+CARGO --args="build --release" --output="release/[^/\.]+" | ||
SAVE ARTIFACT target/release/yage | ||
|
||
prebuilt: | ||
LOCALLY | ||
ARG --required platform_slug | ||
ARG --required target | ||
RUN mkdir -p bin \ | ||
&& cp target/$target/release/yage bin/yage-$platform_slug | ||
DO rust+CARGO --args="fetch" | ||
|
||
cross: | ||
LOCALLY | ||
ARG --required platform_slug | ||
ARG --required target | ||
RUN rm -rf target/release \ | ||
&& cross build --target $target --release \ | ||
&& mkdir -p bin \ | ||
&& cp target/$target/release/yage bin/yage-$platform_slug | ||
|
||
cross-dind: | ||
FROM rust:alpine | ||
RUN apk add --no-cache musl-dev findutils | ||
DO rust+INIT --keep_fingerprints=true | ||
DO rust+SET_CACHE_MOUNTS_ENV | ||
DO rust+CARGO --args="install cross" | ||
RUN apk add docker jq | ||
ARG --required target | ||
COPY --keep-ts . ./ | ||
WITH DOCKER | ||
FROM +cross-deps | ||
ARG TARGETPLATFORM | ||
ARG target=$(/target.sh $TARGETPLATFORM) | ||
# RUN rustup target add $target | ||
WITH DOCKER --pull ghcr.io/cross-rs/$target:$CROSS_VERSION | ||
RUN --mount=$EARTHLY_RUST_CARGO_HOME_CACHE \ | ||
--mount=$EARTHLY_RUST_TARGET_CACHE \ | ||
cross build --target $target --release | ||
END | ||
DO rust+COPY_OUTPUT --output="[^\./]+/release/[^\./]+" | ||
|
||
artifact: | ||
FROM alpine | ||
ARG TARGETPLATFORM | ||
RUN echo "Building for $TARGETPLATFORM" | ||
ARG platform_slug=$(echo $TARGETPLATFORM | tr / -) | ||
ARG build=earthly | ||
COPY platform.sh /platform.sh | ||
ARG target=$(/platform.sh $TARGETPLATFORM) | ||
IF [ "$build" = "earthly" ] | ||
COPY +build/yage /yage | ||
ELSE IF [ "$build" = "prebuilt" ] | ||
WAIT | ||
BUILD +prebuilt --platform_slug=$platform_slug --target=$target | ||
END | ||
COPY bin/yage-$platform_slug /yage | ||
ELSE IF [ "$build" = "cross" ] | ||
WAIT | ||
BUILD +cross --platform_slug=$platform_slug --target=$target | ||
END | ||
COPY bin/yage-$platform_slug /yage | ||
ELSE IF [ "$build" = "cross-dind" ] | ||
WAIT | ||
ARG NATIVEPLATFORM | ||
BUILD --platform $NATIVEPLATFORM +cross --target=$target | ||
END | ||
COPY bin/yage-$platform_slug /yage | ||
rm -rf target/release \ | ||
&& cross build --target $target --release | ||
END | ||
SAVE ARTIFACT yage | ||
DO rust+COPY_OUTPUT --output=".+/release/[^\./]+" | ||
SAVE ARTIFACT /app/target/$target/release/yage | ||
|
||
docker: | ||
FROM scratch | ||
docker-build: | ||
ARG from=scratch | ||
FROM $from | ||
WORKDIR /app | ||
ARG build=earthly | ||
COPY (+artifact/yage --build=$build) /yage | ||
COPY +cross/yage /yage | ||
# make sure we have the required dependencies in the image | ||
# can't do that unfortunately because of https://github.com/earthly/earthly/issues/2618 | ||
# RUN ["/yage", "--help"] | ||
ENTRYPOINT ["/yage"] | ||
ARG tag=main | ||
# SAVE IMAGE --push glehmann/yage:$tag | ||
SAVE IMAGE --push ghcr.io/glehmann/yage:$tag | ||
|
||
docker: | ||
FROM alpine | ||
ARG TARGETPLATFORM | ||
COPY docker/from.sh / | ||
ARG from=$(/from.sh $TARGETPLATFORM) | ||
ARG tag=main | ||
BUILD +docker-build --from=$from --tag=main | ||
|
||
docker-multiplatform: | ||
ARG build=earthly | ||
ARG tag=main | ||
BUILD \ | ||
--platform=linux/amd64 \ | ||
--platform=linux/arm64 \ | ||
--platform=linux/386 \ | ||
--platform=linux/arm/v7 \ | ||
--platform=linux/arm/v6 \ | ||
--platform=linux/ppc64le \ | ||
# --platform=linux/s390x \ | ||
+docker --build=$build | ||
--platform=linux/s390x \ | ||
+docker --tag=$tag |
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,14 @@ | ||
#!/bin/sh | ||
|
||
case "$1" in | ||
"linux/amd64") target='scratch' ;; | ||
"linux/arm64") target='scratch' ;; | ||
"linux/386") target='scratch' ;; | ||
"linux/arm/v7") target='scratch' ;; | ||
"linux/arm/v6") target='scratch' ;; | ||
"linux/ppc64le") target='debian:12-slim' ;; | ||
"linux/s390x") target='debian:12-slim' ;; | ||
*) echo >&2 "error: unsupported $TARGETPLATFORM architecture"; exit 1 ;; | ||
esac; | ||
|
||
echo -n $target |
File renamed without changes.