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: improve devcontainer experience #1251

Merged
merged 13 commits into from
May 7, 2024
Merged
46 changes: 17 additions & 29 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,33 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/alpine
// For format details, see https://aka.ms/devcontainer.json.
{
"name": "Bluefin-devcontainer",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/base:alpine-3.19",

"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"customizations": {
"vscode": {
"extensions": [
"eamodio.gitlens",
"hangxingliu.vscode-systemd-support",
"mads-hartmann.bash-ide-vscode",
"ms-azuretools.vscode-docker",
"sclu1034.justfile",
"timonwong.shellcheck"
]
}
},

"containerEnv": {
"HOME": "/home/vscode"
},

// Likely need to add "--userns=keep-id, --group-add=keep-groups" for podman support
"runArgs": ["--init"],
"remoteEnv": { "LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}" },
"securityOpt": [
"label=disable"
],

"runArgs": [
"--userns=keep-id"
]

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "uname -a",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
"features": {
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {},
"ghcr.io/guiyomh/features/just:0": {},
"ghcr.io/lukewiwa/features/shellcheck:0": {}
},
"onCreateCommand": {
"bash-completions": "sudo apt-get install -y bash-completion; echo 'source /etc/profile.d/bash_completion.sh' | sudo tee -a /etc/bash.bashrc > /dev/null",
"just-completions": "just --completions bash | sudo tee -a /etc/bash_completion.d/just > /dev/null",
"docker-completions": "docker completion bash | sudo tee -a /etc/bash_completion.d/docker.sh > /dev/null"
}
}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.iso
*_flatpaks/flatpaks_with_deps
flatpak.*

scripts/files/home/ublue-os/*
12 changes: 9 additions & 3 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
ARG BASE_IMAGE_NAME="${BASE_IMAGE_NAME:-silverblue}"
ARG IMAGE_FLAVOR="${IMAGE_FLAVOR:-main}"
ARG AKMODS_FLAVOR="${AKMODS_FLAVOR:-main}"
ARG SOURCE_IMAGE="${SOURCE_IMAGE:-$BASE_IMAGE_NAME-$IMAGE_FLAVOR}"
ARG SOURCE_IMAGE="${SOURCE_IMAGE:-${BASE_IMAGE_NAME}-${IMAGE_FLAVOR}}"
ARG BASE_IMAGE="ghcr.io/ublue-os/${SOURCE_IMAGE}"
ARG FEDORA_MAJOR_VERSION="${FEDORA_MAJOR_VERSION:-40}"
ARG TARGET_BASE="${TARGET_BASE:-bluefin}"

# KMODs
ARG KMOD_SOURCE_COMMON="ghcr.io/ublue-os/akmods:${AKMODS_FLAVOR}-${FEDORA_MAJOR_VERSION}"
ARG KMOD_SOURCE_EXTRA="ghcr.io/ublue-os/akmods-extra:${AKMODS_FLAVOR}-${FEDORA_MAJOR_VERSION}"
FROM ${KMOD_SOURCE_COMMON} as akmod-common
FROM ${KMOD_SOURCE_EXTRA} as akmod-extra

## bluefin image section
FROM ${BASE_IMAGE}:${FEDORA_MAJOR_VERSION} AS base

Expand All @@ -28,7 +34,7 @@ COPY /system_files/shared/usr/etc/ublue-update/ublue-update.toml /tmp/ublue-upda
COPY --from=ghcr.io/ublue-os/bluefin-cli /usr/bin/atuin /usr/bin/atuin
COPY --from=ghcr.io/ublue-os/bluefin-cli /usr/share/bash-prexec /usr/share/bash-prexec
# COPY ublue kmods, add needed negativo17 repo and then immediately disable due to incompatibility with RPMFusion
COPY --from=ghcr.io/ublue-os/akmods:${AKMODS_FLAVOR}-${FEDORA_MAJOR_VERSION} /rpms /tmp/akmods-rpms
COPY --from=akmod-common /rpms /tmp/akmods-rpms

# Build, cleanup, commit.
RUN rpm-ostree cliwrap install-to-root / && \
Expand All @@ -54,7 +60,7 @@ COPY system_files/dx /
COPY packages.json /tmp/packages.json

# Copy akmods-extra from ublue
COPY --from=ghcr.io/ublue-os/akmods-extra:${AKMODS_FLAVOR}-${FEDORA_MAJOR_VERSION} /rpms /tmp/akmods-rpms
COPY --from=akmod-extra /rpms /tmp/akmods-rpms

# Build, Clean-up, Commit
RUN bash -c ". /tmp/build/build-dx.sh" && \
Expand Down
91 changes: 91 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
export project_root := `git rev-parse --show-toplevel`
export gts := "39"
export latest := "40"

alias run := run-booted-guest

_default:
@just help

_container_mgr:
@{{project_root}}/scripts/container_mgr.sh

_base_image image:
@{{project_root}}/scripts/base-image.sh {{image}}

_tag image target:
@{{project_root}}/scripts/make-tag.sh {{image}} {{target}}

# Build Image
build image="" target="" version="":
@{{project_root}}/scripts/build-image.sh {{image}} {{target}} {{version}}

# Run image
run-container image="" target="" version="":
@{{project_root}}/scripts/run-image.sh {{image}} {{target}} {{version}}

# Run Booted Image Session w/ Guest
run-booted-guest image="" target="" version="":
@{{project_root}}/scripts/run-booted-guest.sh {{image}} {{target}} {{version}}

# Run Booted Image Session w/ mounted in $USER and $HOME
run-booted-home image="" target="" version="":
@{{project_root}}/scripts/run-booted-home.sh {{image}} {{target}} {{version}}

# Create ISO from local dev build image
build-iso image="" target="" version="":
@{{project_root}}/scripts/build-iso.sh {{image}} {{target}} {{version}}

# Create ISO from currenct ghcr image
build-iso-ghcr image="" target="" version="":
@{{project_root}}/scripts/build-iso-ghcr.sh {{image}} {{target}} {{version}}

# Clean Directory. Remove ISOs and Build Files
clean:
@{{project_root}}/scripts/cleanup-dir.sh

# Remove built images
clean-images:
@{{project_root}}/scripts/cleanup-images.sh

# List Built Images
list-images:
@{{project_root}}/scripts/list-images.sh

[private]
help:
#!/usr/bin/bash
echo " "
echo "These are helper scripts for building and testing development images "
echo " "
echo "You can run dev images either in 'booted like' setup with 'just run-booted' "
echo "Or in a more stripped down version with 'just run' "
echo "Specify which image you wish to build and run by name. "
echo "Example: 'just run-container aurora' -> runs aurora without systemd "
echo "Example: 'just run bluefin-dx' -> runs bluefin-dx with systemd "
echo " "
echo "Helper scripts are in 'project_root/scripts'. "
echo " "
echo "Modify the 'devcontainer.json' in 'project_root/.devcontainer' to support "
echo "Running the devcontainer with podman or docker "
echo "Manually specify container manager with '$CONTAINER_MGR' enviornment variable "
echo " "
just --list

# Build Bluefin
bluefin: (build "bluefin" "base" "{{gts}}")

# Build Bluefin-DX
bluefin-dx: (build "bluefin" "dx" "{{gts}}")

# Build Bluefin Latest
bluefin-latest: (build "bluefin" "base" "{{latest}}")

# Build Bluefin-DX Latest
bluefin-dx-latest: (build "bluefin" "dx" "{{latest}}")

# Build Aurora
aurora: (build "aurora" "base" "{{latest}}")

# Builed Aurora-DX
aurora-dx: (build "aurora" "dx" "{{latest}}")
1 change: 0 additions & 1 deletion build_files/base/copr-repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ curl -Lo /etc/yum.repos.d/ublue-os-staging-fedora-"${FEDORA_MAJOR_VERSION}".repo
# Add Bling repo
curl -Lo /etc/yum.repos.d/ublue-os-bling-fedora-"${FEDORA_MAJOR_VERSION}".repo https://copr.fedorainfracloud.org/coprs/ublue-os/bling/repo/fedora-"${FEDORA_MAJOR_VERSION}"/ublue-os-bling-fedora-"${FEDORA_MAJOR_VERSION}".repo


# 39 Ptyxis
if [ "${FEDORA_MAJOR_VERSION}" -eq "39" ]; then
curl -Lo /etc/yum.repos.d/_copr_kylegospo-gnome-vrr.repo https://copr.fedorainfracloud.org/coprs/kylegospo/gnome-vrr/repo/fedora-"${FEDORA_MAJOR_VERSION}"/kylegospo-gnome-vrr-fedora-"${FEDORA_MAJOR_VERSION}".repo
Expand Down
2 changes: 2 additions & 0 deletions build_files/base/systemd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ systemctl enable dconf-update.service
systemctl --global enable ublue-flatpak-manager.service
systemctl enable ublue-update.timer
systemctl enable ublue-system-setup.service
systemctl enable ublue-etc-merge.service
systemctl enable ublue-guest-user.service
systemctl --global enable ublue-user-setup.service
systemctl --global enable podman-auto-update.timer
12 changes: 12 additions & 0 deletions scripts/base-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/bash
set -euo pipefail

image=$1

if [[ ${image} =~ "bluefin" ]]; then
echo silverblue
elif [[ ${image} =~ "aurora" ]]; then
echo kinoite
else
exit 1
fi
32 changes: 32 additions & 0 deletions scripts/build-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/bash
set -eo pipefail
if [[ -z ${project_root} ]]; then
project_root=$(git rev-parse --show-toplevel)
fi

# Get Inputs
image=$1
target=$2
version=$3

# Set image/target/version based on inputs
# shellcheck disable=SC2154,SC1091
. "${project_root}/scripts/get-defaults.sh"

# Get info
container_mgr=$(just _container_mgr)
base_image=$(just _base_image "${image}")
tag=$(just _tag "${image}" "${target}")

# Build Image
$container_mgr build -f Containerfile \
--build-arg="AKMODS_FLAVOR=main" \
--build-arg="BASE_IMAGE_NAME=${base_image}" \
--build-arg="SOURCE_IMAGE=${base_image}-main" \
--build-arg="FEDORA_MAJOR_VERSION=${version}" \
--build-arg="IMAGE_NAME=${tag}" \
--build-arg="IMAGE_FLAVOR=main" \
--build-arg="IMAGE_VENDOR=localhost" \
--tag localhost/"${tag}":"${version}" \
--target "${target}" \
"${project_root}"
27 changes: 27 additions & 0 deletions scripts/build-iso-ghcr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/bash
#shellcheck disable=SC2154

if [[ -z ${project_root} ]]; then
project_root=$(git rev-parse --show-toplevel)
fi

# Common Build ISO
# shellcheck disable=SC2154,SC1091
. "${project_root}/scripts/common-build-iso.sh"

# Make ISO
${container_mgr} run --rm --privileged --volume "${workspace}":/build-container-installer/build \
ghcr.io/jasonn3/build-container-installer:latest \
ARCH="x86_64" \
ENABLE_CACHE_DNF="false" \
ENABLE_CACHE_SKOPEO="false" \
ENABLE_FLATPAK_DEPENDENCIES="false" \
ENROLLMENT_PASSWORD="ublue-os" \
FLATPAK_REMOTE_REFS_DIR="${flatpak_dir_shortname}" \
IMAGE_NAME="${ghcr_tag}" \
IMAGE_REPO="ghcr.io/ublue-os" \
IMAGE_TAG="${version}" \
ISO_NAME="${ghcr_tag}-${version}-ghcr.iso" \
SECURE_BOOT_KEY_URL='https://github.com/ublue-os/akmods/raw/main/certs/public_key.der' \
VARIANT="${variant}" \
VERSION="${version}"
29 changes: 29 additions & 0 deletions scripts/build-iso.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/bash
#shellcheck disable=SC2154

if [[ -z ${project_root} ]]; then
project_root=$(git rev-parse --show-toplevel)
fi

# Common Build ISO
# shellcheck disable=SC1091
. "${project_root}/scripts/common-build-iso.sh"

# Make ISO
${container_mgr} run --rm --privileged \
--volume "${workspace}"/scripts/files/build-iso-makefile-patch:/build-container-intaller/container/Makefile \
--volume "${workspace}":/build-container-installer/build \
ghcr.io/jasonn3/build-container-installer:latest \
ARCH="x86_64" \
ENABLE_CACHE_DNF="false" \
ENABLE_CACHE_SKOPEO="false" \
ENABLE_FLATPAK_DEPENDENCIES="false" \
ENROLLMENT_PASSWORD="ublue-os" \
FLATPAK_REMOTE_REFS_DIR="${flatpak_dir_shortname}" \
IMAGE_NAME="${tag}" \
IMAGE_REPO="localhost" \
IMAGE_TAG="${version}" \
ISO_NAME="${tag}-${version}.iso" \
SECURE_BOOT_KEY_URL='https://github.com/ublue-os/akmods/raw/main/certs/public_key.der' \
VARIANT="${variant}" \
VERSION="${version}"
12 changes: 12 additions & 0 deletions scripts/cleanup-dir.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/bash
if [[ -z ${project_root} ]]; then
project_root=$(git rev-parse --show-toplevel)
fi

set -euox pipefail

#shellcheck disable=SC2154
rm -f "${project_root}"/*.iso
rm -f "${project_root}"/*_flatapks/flatpaks_with_deps
rm -rf "${project_root}"/flatpak.*
rm -rf "${project_root}"/scripts/files/home/ublue-os/*
15 changes: 15 additions & 0 deletions scripts/cleanup-images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/bash
set -euox pipefail
container_mgr=(
docker
podman
podman-remote
)
for i in "${container_mgr[@]}"; do
if [[ $(command -v "$i") ]]; then
echo "Container Manager: ${i}"
ID=$(${i} images --filter "reference=localhost/bluefin*-build" --filter "reference=localhost/aurora*-build" --format "{{.ID}}")
xargs -I {} "${i}" image rm {} <<< "$ID"
echo ""
fi
done
Loading
Loading