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

fix: Better support distrobox #160

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions Dockerfile.alpine

This file was deleted.

21 changes: 0 additions & 21 deletions Dockerfile.fedora

This file was deleted.

60 changes: 44 additions & 16 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ run-checks:

build-images:
BUILD +blue-build-cli
BUILD +blue-build-cli-alpine
BUILD +blue-build-cli-distrobox
BUILD +installer

prebuild:
BUILD +blue-build-cli-prebuild
BUILD +blue-build-cli-alpine-prebuild
BUILD +blue-build-cli-distrobox-prebuild

lint:
FROM +common
Expand Down Expand Up @@ -110,22 +110,39 @@ build-scripts:
DO --pass-args +SAVE_IMAGE --IMAGE="$IMAGE/build-scripts"

blue-build-cli-prebuild:
ARG BASE_IMAGE="registry.fedoraproject.org/fedora-toolbox:40"
FROM DOCKERFILE -f Dockerfile.fedora .
ARG BASE_IMAGE="registry.fedoraproject.org/fedora-toolbox"
FROM "$BASE_IMAGE"

RUN dnf -y install dnf-plugins-core \
&& dnf config-manager addrepo \
--from-repofile=https://download.docker.com/linux/fedora/docker-ce.repo \
&& dnf install --refresh -y docker-ce docker-ce-cli containerd.io \
docker-buildx-plugin docker-compose-plugin \
buildah podman skopeo dumb-init git

ENTRYPOINT ["/usr/bin/dumb-init", "--"]

COPY --platform=native (+digest/base-image-digest --BASE_IMAGE=$BASE_IMAGE) /base-image-digest
LABEL org.opencontainers.image.base.name="$BASE_IMAGE"
LABEL org.opencontainers.image.base.digest="$(cat /base-image-digest)"

COPY +cosign/cosign /usr/bin/cosign

ARG EARTHLY_GIT_HASH
ARG TARGETARCH
SAVE IMAGE --push "$IMAGE:$EARTHLY_GIT_HASH-prebuild-$TARGETARCH"

blue-build-cli:
ARG EARTHLY_GIT_HASH
FROM alpine
ARG RELEASE="true"
ARG TARGETARCH
FROM "$IMAGE:$EARTHLY_GIT_HASH-prebuild-$TARGETARCH"

IF [ "$RELEASE" = "true" ]
ARG EARTHLY_GIT_HASH
FROM "$IMAGE:$EARTHLY_GIT_HASH-prebuild-$TARGETARCH"
ELSE
FROM +blue-build-cli-prebuild
END

IF [ "$TARGETARCH" = "arm64" ]
DO --pass-args +INSTALL --OUT_DIR="/usr/bin/" --BUILD_TARGET="aarch64-unknown-linux-gnu"
Expand All @@ -139,9 +156,24 @@ blue-build-cli:

DO --pass-args +SAVE_IMAGE

blue-build-cli-alpine-prebuild:
blue-build-cli-distrobox-prebuild:
ARG BASE_IMAGE="alpine"
FROM DOCKERFILE -f Dockerfile.alpine .
FROM $BASE_IMAGE

RUN apk update && apk add --no-cache \
alpine-base git dumb-init buildah \
podman skopeo bash-completion docs \
gcompat libc-utils lsof man-pages \
mandoc musl-utils openssh-client-default \
pinentry tar vte3 which \
bash bc bzip2 coreutils curl diffutils findmnt \
findutils gnupg gpg iproute2 iputils keyutils \
less libcap ncurses ncurses-terminfo net-tools \
pigz rsync shadow sudo tcpdump tree tzdata unzip \
util-linux util-linux-misc vulkan-loader wget \
xauth xz zip procps

ENTRYPOINT ["/usr/bin/dumb-init", "--"]

COPY --platform=native (+digest/base-image-digest --BASE_IMAGE=$BASE_IMAGE) /base-image-digest
LABEL org.opencontainers.image.base.name="$BASE_IMAGE"
Expand All @@ -151,24 +183,20 @@ blue-build-cli-alpine-prebuild:

ARG EARTHLY_GIT_HASH
ARG TARGETARCH
SAVE IMAGE --push "$IMAGE:$EARTHLY_GIT_HASH-alpine-prebuild-$TARGETARCH"
SAVE IMAGE --push "$IMAGE:$EARTHLY_GIT_HASH-distrobox-prebuild-$TARGETARCH"

blue-build-cli-alpine:
blue-build-cli-distrobox:
ARG EARTHLY_GIT_HASH
ARG TARGETARCH
FROM "$IMAGE:$EARTHLY_GIT_HASH-alpine-prebuild-$TARGETARCH"
FROM "$IMAGE:$EARTHLY_GIT_HASH-distrobox-prebuild-$TARGETARCH"

IF [ "$TARGETARCH" = "arm64" ]
DO --pass-args +INSTALL --OUT_DIR="/usr/bin/" --BUILD_TARGET="aarch64-unknown-linux-musl"
ELSE
DO --pass-args +INSTALL --OUT_DIR="/usr/bin/" --BUILD_TARGET="x86_64-unknown-linux-musl"
END

RUN mkdir -p /bluebuild
WORKDIR /bluebuild
CMD ["bluebuild"]

DO --pass-args +SAVE_IMAGE --SUFFIX="-alpine"
DO --pass-args +SAVE_IMAGE --SUFFIX="-distrobox"

installer:
ARG BASE_IMAGE="alpine"
Expand Down
48 changes: 8 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ The `bluebuild` tool takes advantage of newer build features. Specifically bind,

## Installation

Every image created with `bluebuild` comes with the CLI installed. If you have not built and booted a `bluebuild` created image, you can follow these instructions to install it.

### Cargo

This is the best way to install as it gives you the opportunity to build for your specific environment.
Expand All @@ -28,7 +30,7 @@ cargo install --locked blue-build

### Podman/Docker

This will install the binary on your system in `/usr/local/bin`. This is only a `linux-gnu` version.
This will install the binary on your system in `/usr/local/bin`.

```bash
podman run --pull always --rm ghcr.io/blue-build/cli:latest-installer | bash
Expand All @@ -46,41 +48,15 @@ bash <(curl -s https://raw.githubusercontent.com/blue-build/cli/main/install.sh)

### Distrobox

[distrobox-export-documentation]: https://distrobox.it/usage/distrobox-export/

We package a `fedora-toolbox` and `alpine` image with all the tools needed to run `bluebuild`. You can use `distrobox` to run the application without needing to install it on your machine.

```bash
# fedora-toolbox
distrobox create blue-build --image ghcr.io/blue-build/cli
# alpine
distrobox create blue-build --image ghcr.io/blue-build/cli:latest-alpine
```

By default, the bluebuild commands will not be visible outside of the distrobox itself. You will need to **enter** the distrobox, and either run the commands from inside the distrobox, or **export** the distrobox commands for use outside the distrobox.

Refer to the [distrobox documentation][distrobox-export-documentation] for more information.

#### Running commands from within distrobox
We package an `alpine` image with all the tools needed to run `bluebuild`. You can use `distrobox` to run the application without needing to install it on your machine. You can clone this repo locally and run:

```bash
[user@host]$ bluebuild help
ERROR
[user@host]$ distrobox enter blue-build
[user@blue-build]$ bluebuild help
A CLI tool built for creating Containerfile templates based on the Ublue Community Project
...
distrobox assemble create
```

#### Exporting commands to run outside distrobox
This will export `bluebuild` to your local machine and allow you to build images and test out your recipes. For security reasons, we keep this as a rootless image which means you will not be able to use this method to locally rebase to an image. If you want that capability, you should install the CLI tool directly.

```bash
[user@blue-build]$ distrobox-export --bin $(which bluebuild)
[user@blue-build]$ exit
[user@host]$ bluebuild help
A CLI tool built for creating Containerfile templates based on the Ublue Community Project
...
```
Refer to the [distrobox documentation](https://distrobox.it/usage/distrobox-export/) for more information.

### Nix Flake

Expand Down Expand Up @@ -167,7 +143,7 @@ $ bluebuild # press <Tab>
-h --quiet build rebase help
```

Currently, bluebuild completions are available for `bash`, `zsh`, `fish`, `powershell`, and `elvish` shell environments.
Currently, bluebuild completions are available for `bash`, `zsh`, `fish`, `powershell`, and `elvish` shell environments. Please follow your shell's documentation for completion scripts.

#### Local Builds

Expand Down Expand Up @@ -290,11 +266,3 @@ build-image:
- sleep 5 # Wait a bit for the docker-in-docker service to start
- bluebuild build --push ./recipes/$RECIPE
```

## Future Features

- Stages for parallel building (useful for compiling programs for your image)
- Automatic download and management of image keys for seamless signed image rebasing
- Module command for easy 3rd party plugin management
- Create an init command to create a repo for you to start out
- Setup the project to allow installing with `cargo-binstall`
7 changes: 7 additions & 0 deletions distrobox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[bluebuild]
image=ghcr.io/blue-build/cli:latest-distrobox
exported_bins=/usr/bin/bluebuild
init_hooks=ln -sf /usr/bin/distrobox-host-exec /usr/local/bin/podman
pull=true
replace=true
start_now=true
8 changes: 3 additions & 5 deletions integration-tests/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ init:
--no-git

legacy-base:
FROM ../+blue-build-cli-alpine --RELEASE=false
RUN apk update --no-cache && apk add bash grep jq sudo coreutils
FROM ../+blue-build-cli --RELEASE=false
ENV BB_TEST_LOCAL_IMAGE=/etc/bluebuild/cli_test-legacy.tar.gz
ENV CLICOLOR_FORCE=1

Expand All @@ -140,9 +139,8 @@ legacy-base:
DO +GEN_KEYPAIR

test-base:
FROM ../+blue-build-cli-alpine --RELEASE=false
RUN apk update --no-cache && apk add bash grep jq sudo coreutils git && \
git config --global user.email "[email protected]" && \
FROM ../+blue-build-cli --RELEASE=false
RUN git config --global user.email "[email protected]" && \
git config --global user.name "Your Name"

ENV BB_TEST_LOCAL_IMAGE=/etc/bluebuild/cli_test.tar.gz
Expand Down
21 changes: 21 additions & 0 deletions integration-tests/mock-scripts/docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

print_version_json() {
local version="24.0.0"
printf '{"Client":{"Version": "%s"}}\n' "$version"
}

main() {
if [[ "$1" == "version" && "$2" == "-f" && "$3" == "json" ]]; then
print_version_json
elif [[ "$1" == "build" && "$7" == *"cli_test.tar.gz" ]]; then
tarpath=$(echo "$7" | awk -F ':' '{print $2}')
echo "Exporting image to a tarball (JK JUST A MOCK!)"
echo "${tarpath}"
touch $tarpath
else
echo 'Running docker'
fi
}

main "$@"
Loading