Skip to content

Commit

Permalink
🏋️‍♂️Putting the image on a serious diet (v4.0.0) (#13)
Browse files Browse the repository at this point in the history
* Test Alpine linux (See Jerrylum/pros-build)

* Update Dockerfile

* Update Dockerfile

* Use pipx

* Update Dockerfile

* Add root/.local/bin to path

* Make build.sh in the root folder

* Try specifying filename where to copy build.sh to

* Update Dockerfile

* Update Dockerfile

* Change /build.sh to ~/build.sh

* Update Dockerfile

* Update Dockerfile

* add sh and bash for good measure

* Update Dockerfile

* Put the toolchain on a serious diet

* Comment out G++

* forgot to uncomment the path 💀

* add G++ back in

* run ldd on each program in the dieted toolchain

* try ldd again

* Update Dockerfile

* Update copied files

* Change non-dieted files.

* Add libexec to included files

* add possibly missing /

* Update Dockerfile

* Remove extra folder from mkdir

* remove -r flag

* include arm-none-eabi/lib too

* pivot to deleting stuff from the toolchain folder instead of selectively copying stuff. Starting with arm-none-eabi folder

* Delete share folder instead

* try deleting arm-none-eabi/lib

* forgot the folder prefix

* delete /lib/gcc/arm-none-eabi/13.3.1/arm and /lib/gcc/arm-none-eabi/13.3.1/thumb

* delete all but v7-a+fp in thumb

* forgot /arm-none-eabi-toolchain prefix again

* remove files in RUN rm -f /arm-none-eabi-toolchain/lib/gcc/arm-none-eabi/13.3.1/* but not folders

* Update Dockerfile

* Update action.yml to test externally

* Update Dockerfile with stages

* fix copy from stage

* comment out rm command to test stages

* add back package installation

* Update Dockerfile

* refactor to have more stages

* Update Dockerfile

* Update build-image.yml

* Update build-image.yml

* Update build-image.yml

* Remove line that deletes all 13.3.1 subfiles and subfolders

* Diet some more files 

arm-none-eabi-cpp, arm-none-eabi-gdb, arm-none-eabi-gcc-13.3.1,

* Change dieted files to their actual location (misread on my part)

* Update Dockerfile

* diet some more folders

* we cut too much

* Update build.sh

* Update test.yml

* revert back

* revert back

* Update action.yml

* also remove gbd-py from toolchain bin folder

* Update Dockerfile

* re-add pros-cli

* steal additional thumb deleting from jerryio's container

* Update Dockerfile labels

* Update Dockerfile

* Thanks to @Jerrylum

* Remove total build script runtime from build.sh as it's confusing

* Delete packagelist

* Update README.md

* Update action.yml with v4.0.0

* remove pruning steps

* Update build.sh to use shell instead of bash

* remove bash

* Restore bash

* ♻️ Improved run instruction (#14)

* ♻️ Improved run instruction
- Makes it a little more readable by using heredoc
- Pipes tar.xz to tar to prevent writing it to disk
- Uses brace expansion where possible to shorten
- Don't even write some of the unnecessary files to disk

* split toolchain downloading into seperate RUN command for caching efficency and convert all tar --exclude params to their original rm/find forms.

* Fix broken gcc rm command for /bin/arm-none-eabi-gcc-13.3.1

* fix gcc-13.3.1 removal

* delete long_toolchain variable

* 💄 Remove extra whitespace

* remove package installation from get-dependencies since it's already redone in runner stage and the packages aren't used in the get-deps stage

---------

Co-authored-by: ABUCKY0 <[email protected]>

* Delete commented commands for clarity

---------

Co-authored-by: Andrew Curtis <[email protected]>
  • Loading branch information
ABUCKY0 and meisZWFLZ authored Jan 3, 2025
1 parent 272e63b commit 1a3f11c
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,4 @@ jobs:
for tag in $(echo "${{ steps.load.outputs.tag }}" | tr ' ' '\n'); do
echo "$tag"
docker push "$tag"
done
done
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ jobs:
with:
name: "${{ steps.test-action.outputs.name }}${{ inputs.artifact_additional_postfix }}"
path: "template/*"

- name: Add Artifact to Job Summary
if: ${{ inputs.upload_artifact && !inputs.expect_error }}
run: 'echo "### 📦 Artifact url: ${{ steps.upload.outputs.artifact-url }}" >> $GITHUB_STEP_SUMMARY'
94 changes: 40 additions & 54 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,70 +1,56 @@
FROM ubuntu:20.04
# ------------
# Build Stage: Get Dependencies
# ------------
FROM alpine:latest AS get-dependencies
LABEL stage=builder

LABEL org.opencontainers.image.description="A PROS Build Container"
LABEL org.opencontainers.image.source=https://github.com/lemlib/pros-build
LABEL org.opencontainers.image.licenses=MIT
# ------------
# Install Required Packages
# ------------
COPY packagelist /packagelist
RUN apt-get update && apt-get install -y $(cat /packagelist) && apt-get clean
RUN rm /packagelist # Cleanup Image

# ------------
# Set Timezone and set frontend to noninteractive
# ------------
ENV DEBIAN_FRONTEND=noninteractive
RUN echo "tzdata tzdata/Areas select America" | debconf-set-selections \
&& echo "tzdata tzdata/Zones/America select Los_Angeles" | debconf-set-selections
# Install Required Packages and ARM Toolchain
RUN apk add --no-cache bash
RUN mkdir "/arm-none-eabi-toolchain" && wget -O- "https://developer.arm.com/-/media/Files/downloads/gnu/13.3.rel1/binrel/arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-eabi.tar.xz" \
| tar Jxf - -C "/arm-none-eabi-toolchain" --strip-components=1
RUN <<-"EOF" bash
set -e

# ------------
# Install ARM Toolchain
# ------------
RUN wget "https://developer.arm.com/-/media/Files/downloads/gnu/13.3.rel1/binrel/arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-eabi.tar.xz" -O arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-eabi.tar.xz
RUN tar xf arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-eabi.tar.xz
RUN rm arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-eabi.tar.xz # Cleanup Image
RUN mv "/arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-eabi" "/arm-none-eabi-toolchain"
ENV PATH="/arm-none-eabi-toolchain/bin:${PATH}"
toolchain="/arm-none-eabi-toolchain"
mkdir -p "$toolchain"

# ------------
# Install PROS CLI
# ------------
RUN python3 -m pip install pros-cli
rm -rf "$toolchain"/{share,include}
rm -rf "$toolchain"/lib/gcc/arm-none-eabi/13.3.1/arm
rm -f "$toolchain"/bin/arm-none-eabi-{gdb,gdb-py,cpp,gcc-13.3.1}

find "$toolchain"/arm-none-eabi/lib/thumb -mindepth 1 -maxdepth 1 ! -name 'v7-a+fp' -exec rm -rf {} +
find "$toolchain"/lib/gcc/arm-none-eabi/13.3.1/thumb -mindepth 1 -maxdepth 1 ! -name 'v7-a+fp' -exec rm -rf {} +
find "$toolchain"/arm-none-eabi/include/c++/13.3.1/arm-none-eabi/thumb -mindepth 1 -maxdepth 1 ! -name 'v7-a*' -exec rm -rf {} +

apk cache clean # Cleanup image
EOF
# ------------
# Cleanup
# ------------

# Cleanup APT
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# ------------
# Verify Installation
# ------------
RUN python3 --version
RUN pros --version
RUN arm-none-eabi-g++ --version
RUN arm-none-eabi-gcc --version

RUN git --version
RUN make --version
RUN unzip
RUN awk --version


# ------------
# SETUP BUILD
# Runner Stage
# ------------
FROM alpine:latest AS runner
LABEL stage=runner
LABEL org.opencontainers.image.description="A PROS Build Container"
LABEL org.opencontainers.image.source=https://github.com/lemlib/pros-build
LABEL org.opencontainers.image.licenses=MIT
# Copy dependencies from get-dependencies stage
COPY --from=get-dependencies /arm-none-eabi-toolchain /arm-none-eabi-toolchain
RUN apk add --no-cache gcompat libc6-compat libstdc++ git gawk python3 pipx make unzip bash && pipx install pros-cli && apk cache clean

ENV PROS_PROJECT ${PROS_PROJECT}
ENV REPOSITORY ${REPOSITORY}
ENV LIBRARY_PATH ${LIBRARY_PATH}
# Set Environment Variables
ENV PATH="/arm-none-eabi-toolchain/bin:/root/.local/bin:${PATH}"

RUN env

COPY build-tools/build.sh .
RUN chmod +x ./build.sh
# Setup Build
ENV PROS_PROJECT=${PROS_PROJECT}
ENV REPOSITORY=${REPOSITORY}
ENV LIBRARY_PATH=${LIBRARY_PATH}

COPY LICENSE .
COPY build-tools/build.sh /build.sh
RUN chmod +x /build.sh
COPY LICENSE ./LICENSE

ENTRYPOINT ["/build.sh"]
59 changes: 12 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
[![Build-Image action](https://github.com/LemLib/pros-build/actions/workflows/build-image.yml/badge.svg)](https://github.com/LemLib/pros-build/actions/workflows/build-image.yml)
[![Test action](https://github.com/LemLib/pros-build/actions/workflows/test.yml/badge.svg)](https://github.com/LemLib/pros-build/actions/workflows/test.yml)

This action creates an environment capable of building PROS projects and templates, and builds them using [build.sh](/build-tools/build.sh)
This action creates an environment capable of building PROS projects and templates and builds them using [build.sh](/build-tools/build.sh)

Instructions on creating a custom build script, adding additional packages, and using this image as a base are located at the end of this readme.
Instructions on creating a custom build script, adding additional packages, and using this image as a base are located at the end of this readme.

> [!NOTE]
> Also major thanks to [@JerryLum](https://github.com/jerrylum) for his gracious help and competition in building v4.0.0 to be as fast as it is now!
## Usage:

### Inputs
Expand Down Expand Up @@ -62,7 +64,7 @@ jobs:

- name: Run LemLib/pros-build
id: test
uses: LemLib/pros-build@v3.0.0
uses: LemLib/pros-build@v4.0.0

- name: Upload Artifact
uses: actions/upload-artifact@v4
Expand All @@ -75,22 +77,16 @@ jobs:
If you wish to use your own build script using this container as a base, you can do so with the following:
It by default includes the packages built into the Ubuntu docker image, and contains the additional packages below:
> [!WARNING]
> The container now (v4.* and up) uses Alpine Linux and adds the necessary packages to build a PROS Project. The currently added package is listed below, but your mileage on using anything other than basic make commands in a pros project may vary wildly depending on how you create it.
> We also trimmed the toolchain to be much smaller, so if you've modified your Makefile to use other features you may have to fork this repository and change what is removed from the toolchain.
```
wget (Used to download the toolchain)
git (Used to get the HEAD SHA hash)
gawk (Used to get lines from the user project's Makefile)
python3-minimal (Minimal installation of Python used for pros-cli)
python3-pip (Used to install pros-cli in the Dockerfile)
unzip (Unzips the template so that it can be uploaded to Github Actions)
pros-cli (through python)
```
Installed Packages: `gcompat, libc6-compat, libstdc++, git, gawk, python3, pipx, make, unzip, bash`

### Editing the Dockerfile

```Dockerfile
FROM ghcr.io/LemLib/pros-build:v3.0.0
FROM ghcr.io/LemLib/pros-build:v4.0.0
# Remove the included build script.
RUN rm -rf /build.sh
Expand All @@ -101,39 +97,8 @@ RUN rm -rf /build.sh
ENTRYPOINT []
```

# Example Job Summary Output

# ✅ Build Completed

Build completed in 25 seconds
Total Build Script Runtime: 27 seconds

## 📝 Library Name: LemLib @ 0.5.1

### 🔐 SHA: 4f12f2

### 📁 Artifact Name: [email protected]+4f12f2

---

#### 📄 Output from Make
# Example Job Summary Output

<details><summary>Click to expand</summary>
```
Creating bin/LemLib.a [DONE]
Creating cold package with libpros,libc,libm,LemLib [OK]
Stripping cold package [DONE]
Section sizes:
text data bss total hex filename
1013.69KB 4.89KB 47.15MB 48.14MB 30234f7 bin/cold.package.elf
Adding timestamp [OK]
Linking hot project with ./bin/cold.package.elf and libpros,libc,libm,LemLib [OK]
Section sizes:
text data bss total hex filename
3.97KB 12.00B 46.02MB 46.02MB 2e04a17 bin/hot.package.elf
Creating cold package binary for VEX EDR V5 [DONE]
Creating bin/hot.package.bin for VEX EDR V5 [DONE]
```
</details>
![image](https://github.com/user-attachments/assets/a63ddfc0-5f14-44c0-8e1b-8902f1d99e55)

### 📦 Artifact url: https://github.com/LemLib/pros-build/actions/runs/9426610142/artifacts/1581443703
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ outputs:

runs:
using: 'Docker'
image: 'docker://ghcr.io/lemlib/pros-build:v3.0.0'
image: 'docker://ghcr.io/lemlib/pros-build:v4.0.0'
1 change: 0 additions & 1 deletion build-tools/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ if [[ "$INPUT_WRITE_JOB_SUMMARY" == "true" ]]; then
echo "
# ✅ Build Completed
Build completed in $build_time seconds
Total Build Script Runtime: $(($SECONDS - $script_start_time)) seconds
## 📝 Library Name: ${library_name} @ ${version}
### 🔐 SHA: ${sha}
" >>$GITHUB_STEP_SUMMARY
Expand Down
6 changes: 0 additions & 6 deletions packagelist

This file was deleted.

0 comments on commit 1a3f11c

Please sign in to comment.