Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Unify builder #338

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft
28 changes: 28 additions & 0 deletions earthly/container/Earthfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
VERSION 0.8

IMPORT ../python AS python
IMPORT ../rust AS rust
IMPORT ../flutter AS flutter
IMPORT ../go AS go
IMPORT ../../utilities/scripts AS scripts

main-builder:
FROM debian:stable-slim

WORKDIR /root

RUN apt-get update && \
apt-get install -y \
openssl \
wget \
curl \
graphviz \
bash \
build-essential \
git \
&& rm -rf /var/lib/apt/lists/*

DO python+ADD_PYTHON_TOOLS
DO rust+ADD_RUST_TOOLS
DO flutter+ADD_FLUTTER_TOOLS
DO go+ADD_GO_TOOLS
124 changes: 85 additions & 39 deletions earthly/flutter/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,34 @@ VERSION 0.8

IMPORT ./installer AS installer

# flutter-src save Flutter source code as artifact.
flutter-src:
FROM busybox
ADD_FLUTTER_TOOLS:
FUNCTION
ARG version=3.24.1
ARG TARGETARCH

RUN mkdir -p /flutter
ENV DEBIAN_FRONTEND=noninteractive
# WORKDIR frontend

RUN apt-get update --fix-missing && apt-get install -y \
apt-utils \
gzip \
unzip \
bzip2 \
jq \
gpg \
lcov

# Install Flutter
IF [ "$TARGETARCH" = "amd64" ]
RUN wget -qO - https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_$version-stable.tar.xz \
| tar -xJ -C /flutter
ELSE
GIT CLONE --branch $version https://github.com/flutter/flutter.git /flutter
| tar -xJ -C /usr/local
ELSE IF [ "$TARGETARCH" = "arm64" ]
GIT CLONE --branch $version https://github.com/flutter/flutter.git /usr/local
END
SAVE ARTIFACT /flutter flutter

# flutter-base installs required tools and packages.
flutter-base:
FROM debian:bookworm-20240513-slim

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update --fix-missing
RUN apt-get install -y apt-utils git curl gzip unzip bzip2 bash jq gpg lcov

WORKDIR frontend

DO installer+INSTALL_CHROME_LINUX64
DO installer+INSTALL_FIREFOX_LINUX64

ARG edge_version = 125.0.2535.51
ARG edge_package_release = 1
DO installer+INSTALL_EDGE_LINUX64 --edge_version=$edge_version --edge_package_release=$edge_package_release

COPY +flutter-src/flutter /usr/local
RUN git config --global --add safe.directory /usr/local/flutter
ENV PATH="/usr/local/flutter/bin:/usr/local/flutter/bin/cache/dart-sdk/bin:$HOME/.pub-cache/bin:${PATH}"

RUN flutter config --no-analytics
RUN flutter --version
RUN flutter doctor -v
Expand All @@ -49,17 +42,10 @@ flutter-base:
RUN dart pub global activate combine_coverage
RUN dart pub global activate license_checker

# test-flutter-base-amd64 : installs required tools and packages for amd64.
test-flutter-base-amd64:
BUILD --platform=linux/amd64 +flutter-base

# test-flutter-base-arm64 : installs required tools and packages for arm64.
test-flutter-base-arm64:
BUILD --platform=linux/arm64 +flutter-base

SETUP:
FUNCTION
FROM +flutter-base
# Install browsers
DO installer+INSTALL_CHROME_LINUX64
DO installer+INSTALL_FIREFOX_LINUX64
DO installer+INSTALL_EDGE_LINUX64

# Runs melos bootstrap if melos.yaml file is present.
BOOTSTRAP:
Expand Down Expand Up @@ -121,7 +107,7 @@ FORMAT:
RUN melos run format-check
ELSE
RUN echo "Running flutter format"
RUN flutter format --set-exit-if-changed .
RUN dart format --set-exit-if-changed .
END

# Dry-runs the publish script for publishable packages.
Expand Down Expand Up @@ -191,3 +177,63 @@ BUILD_WEB:
ELSE
SAVE ARTIFACT web /web
END


# -------------delete below this line----------------
# flutter-src save Flutter source code as artifact.
flutter-src:
FROM busybox
ARG version=3.24.1
ARG TARGETARCH

RUN mkdir -p /flutter
IF [ "$TARGETARCH" = "amd64" ]
RUN wget -qO - https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_$version-stable.tar.xz \
| tar -xJ -C /flutter
ELSE
GIT CLONE --branch $version https://github.com/flutter/flutter.git /flutter
END
SAVE ARTIFACT /flutter flutter

# flutter-base installs required tools and packages.
flutter-base:
FROM debian:bookworm-20240513-slim

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update --fix-missing
RUN apt-get install -y apt-utils git curl gzip unzip bzip2 bash jq gpg lcov

WORKDIR frontend

DO installer+INSTALL_CHROME_LINUX64
DO installer+INSTALL_FIREFOX_LINUX64

ARG edge_version = 125.0.2535.51
ARG edge_package_release = 1
DO installer+INSTALL_EDGE_LINUX64 --edge_version=$edge_version --edge_package_release=$edge_package_release

COPY +flutter-src/flutter /usr/local
ENV PATH="/usr/local/flutter/bin:/usr/local/flutter/bin/cache/dart-sdk/bin:$HOME/.pub-cache/bin:${PATH}"
RUN flutter config --no-analytics
RUN flutter --version
RUN flutter doctor -v
RUN flutter config --enable-web
RUN dart pub global activate melos
RUN dart pub global activate junitreport
RUN dart pub global activate coverage
RUN dart pub global activate combine_coverage
RUN dart pub global activate license_checker

# test-flutter-base-amd64 : installs required tools and packages for amd64.
test-flutter-base-amd64:
BUILD --platform=linux/amd64 +flutter-base

# test-flutter-base-arm64 : installs required tools and packages for arm64.
test-flutter-base-arm64:
BUILD --platform=linux/arm64 +flutter-base

SETUP:
FUNCTION
FROM +flutter-base

5 changes: 2 additions & 3 deletions earthly/flutter/installer/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@ INSTALL_EDGE_LINUX64:
LET BLUE ='\033[0;34m'

IF [ "$TARGETARCH" = "amd64" ]
ARG --required edge_version
ARG --required edge_package_release

ARG edge_version = 125.0.2535.51
ARG edge_package_release = 1
RUN printf "${BLUE} Installing Edge..."
RUN curl -LO https://packages.microsoft.com/repos/edge/pool/main/m/microsoft-edge-stable/microsoft-edge-stable_${edge_version}-${edge_package_release}_amd64.deb
RUN apt-get update && apt-get install -y ./microsoft-edge-stable_${edge_version}-${edge_package_release}_amd64.deb
Expand Down
105 changes: 61 additions & 44 deletions earthly/go/Earthfile
Original file line number Diff line number Diff line change
@@ -1,60 +1,56 @@
VERSION 0.8

DEPS:
FUNCTION

# Establish a cache
RUN mkdir -p /go/cache && mkdir -p /go/modcache
ENV GOCACHE=/go/cache
ENV GOMODCACHE=/go/modcache
CACHE --sharing shared /go

COPY go.mod go.sum ./
RUN go mod download

# Install ginkgo for testing - and test it works.
RUN go get github.com/onsi/ginkgo/v2/ginkgo && \
go install github.com/onsi/ginkgo/v2/ginkgo && \
ginkgo version

# Save artifacts that may have been modified
SAVE ARTIFACT go.mod AS LOCAL go.mod
SAVE ARTIFACT go.sum AS LOCAL go.sum

ADD_GO_TOOLS:
FUNCTION

ARG TARGETARCH
RUN apt-get update && \
apt-get install -y \
gcc \
musl-dev \
&& rm -rf /var/lib/apt/lists/*

LET GO_VERSION = "1.23.2"

# Install go
IF [ "$TARGETARCH" = "amd64" ]
LET URL = "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz"
ELSE
LET URL = "https://dl.google.com/go/go${GO_VERSION}.linux-arm64.tar.gz"
END
RUN curl -sSL $URL | tar -xz -C /usr/local

# Set go path
ENV GOROOT="/usr/local/go"
ENV GOPATH="/go"
ENV GOBIN="$GOPATH/bin"
ENV PATH="$PATH:$GOROOT/bin:$GOPATH/bin"

# Install golangci-lint
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh \
| sh -s -- -b $GOBIN v1.61.0 \
&& golangci-lint --version

# Install ginkgo
RUN go install github.com/onsi/ginkgo/ginkgo@v1.16.5 \
&& ginkgo version

FMT:
FUNCTION

# latest linux/amd64
FROM cytopia/gofmt@sha256:ae76abdbc96780819ce175f7ba4bf1fec98e9f708eb680d0b949d1737a959983
WORKDIR /work

ARG --required src
RUN gofmt -l .

FOR f IN ${src}
COPY ${f} /work/${f}
END
FIX_FMT:
FUNCTION

RUN gofmt -l . | grep . && exit 1 || exit 0
ARG --required src
RUN gofmt -w .

LINT:
FUNCTION

# v1.54-alpine
FROM golangci/golangci-lint@sha256:a8423cab177c2863b863ee6d9f00c58f101cadd6120e195b2bb59fdfa189c1ae
WORKDIR /work

ARG --required src

FOR f IN ${src}
COPY ${f} /work/${f}
END

CACHE --sharing shared /cache
ENV GOLANGCI_LINT_CACHE=/cache/golangci-lint
ENV GOCACHE=/cache/go-build

RUN go get ./...

RUN golangci-lint run \
--timeout 5m \
-E errchkjson \
Expand All @@ -65,3 +61,24 @@ LINT:
-E nilnil \
-E revive \
-E testpackage

# -------------delete this line if not needed----------------
DEPS:
FUNCTION

# Establish a cache
RUN mkdir -p /go/cache && mkdir -p /go/modcache
ENV GOCACHE=/go/cache
ENV GOMODCACHE=/go/modcache
CACHE --sharing shared /go

RUN go mod download

# Install ginkgo for testing - and test it works.
RUN go get github.com/onsi/ginkgo/v2/ginkgo && \
go install github.com/onsi/ginkgo/v2/ginkgo && \
ginkgo version

# Save artifacts that may have been modified
SAVE ARTIFACT go.mod AS LOCAL go.mod
SAVE ARTIFACT go.sum AS LOCAL go.sum
Loading
Loading