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(dev): add justfile for local testing and integration with vscode #578

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.idea
*.iso
*.iso-CHECKSUM*
109 changes: 109 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Connect to VM",
"dependsOn": [
"Run-ISO",
"Open Browser"
],
"problemMatcher": []
},
{
"label": "Open Browser",
"command": "${input:openSimpleBrowser}",
"problemMatcher": []
},
{
"label": "Build Container",
"command": "just",
"args": [
"build",
"${input:outputChoice}"
],
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "Build ISO",
"command": "just",
"args": [
"${input:installerChoice}",
"${input:outputChoice}"
],
"problemMatcher": []
},
{
"label": "Run-ISO",
"command": "just",
"args": [
"run-iso",
"${input:outputChoice}"
],
"problemMatcher": [],
"isBackground": true
},
{
"label": "List Images",
"command": "just",
"args": [
"list-images"
],
"problemMatcher": []
},
{
"label": "Run Container",
"command": "just",
"args": [
"run-container",
"${input:outputChoice}"
],
"problemMatcher": []
}
],
"inputs": [
{
"id": "openSimpleBrowser",
"type": "command",
"command": "simpleBrowser.show",
"args": [
"http://localhost:8006"
]
},
{
"id": "installerChoice",
"type": "pickString",
"description": "Choose which Installer Builder to use",
"default": "build-iso",
"options": [
"build-iso",
"build-iso-git"
]
},
{
"id": "outputChoice",
"type": "pickString",
"description": "Choose which container to build",
"default": "silverblue",
"options": [
"silverblue latest",
"kinoite latest",
"sericea latest",
"onyx latest",
"base latest",
"lazurite latest",
"vauxite latest",
"silverblue gts",
"kinoite gts",
"sericea gts",
"onyx gts",
"base gts",
"lazurite gts",
"vauxite gts"
]
}
]
}
7 changes: 5 additions & 2 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ ARG SOURCE_ORG="${SOURCE_ORG:-fedora-ostree-desktops}"
ARG BASE_IMAGE="quay.io/${SOURCE_ORG}/${SOURCE_IMAGE}"
ARG FEDORA_MAJOR_VERSION="${FEDORA_MAJOR_VERSION:-40}"

FROM ghcr.io/ublue-os/config:latest as config
FROM ghcr.io/ublue-os/akmods:main-${FEDORA_MAJOR_VERSION} as akmods

FROM ${BASE_IMAGE}:${FEDORA_MAJOR_VERSION}

ARG IMAGE_NAME="${IMAGE_NAME:-silverblue}"
Expand All @@ -17,8 +20,8 @@ COPY github-release-install.sh \
packages.json \
/tmp/

COPY --from=ghcr.io/ublue-os/config:latest /rpms /tmp/rpms
COPY --from=ghcr.io/ublue-os/akmods:main-${FEDORA_MAJOR_VERSION} /rpms/ublue-os /tmp/rpms
COPY --from=config /rpms /tmp/rpms
COPY --from=akmods /rpms/ublue-os /tmp/rpms
COPY sys_files/usr /usr

RUN mkdir -p /var/lib/alternatives && \
Expand Down
49 changes: 49 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
export project_root := `git rev-parse --show-toplevel`
export git_branch := ` git branch --show-current`
export gts := "39"
export latest := "40"
export default_image := "silverblue"

alias run := run-container
alias build-iso := build-iso-release

_default:
@just --list

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

_tag image:
@echo {{image}}-build

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

# Build ISO
build-iso-release image="" version="":
@{{ project_root }}/just_scripts/build-iso.sh {{image}} {{version}}

# Build ISO using ISO Builder Git Head
build-iso-git image="" version="":
@{{ project_root }}/just_scripts/build-iso-installer-main.sh {{image}} {{version}}

# Run ISO
run-iso image="" version="":
@{{ project_root }}/just_scripts/run-iso.sh {{image}} {{version}}

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

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

# Clean Images
clean-images:
@{{ project_root }}/just_scripts/cleanup-images.sh

# Clean ISOs
clean-isos:
@{{ project_root }}/just_scripts/cleanup-dir.sh
29 changes: 29 additions & 0 deletions just_scripts/build-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/bash
set -eo pipefail
if [[ -z ${project_root} ]]; then
project_root=$(git rev-parse --show-toplevel)
fi
if [[ -z ${git_branch} ]]; then
git_branch=$(git branch --show-current)
fi

# Get Inputs
image=$1
version=$2

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

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

# Build Image
$container_mgr build -f Containerfile \
--build-arg="IMAGE_NAME=${tag}" \
--build-arg="SOURCE_ORG=fedora-ostree-desktops" \
--build-arg="SOURCE_IMAGE=${image}" \
--build-arg="FEDORA_MAJOR_VERSION=${version}" \
--tag localhost/"${tag}:${version}-${git_branch}" \
"${project_root}"
86 changes: 86 additions & 0 deletions just_scripts/build-iso-installer-main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/bash
#shellcheck disable=SC2154,SC2034

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

# shellcheck disable=SC1091
. "${project_root}/just_scripts/sudoif.sh"

# Check if inside rootless container
if [[ -f /run/.containerenv ]]; then
#shellcheck disable=SC1091
source /run/.containerenv
#shellcheck disable=SC2154
if [[ "${rootless}" -eq "1" ]]; then
echo "Cannot build ISO inside rootless podman container... Exiting..."
exit 1
fi
fi
container_mgr=$(just _container_mgr)
# If using rootless container manager, exit. Might not be best check
if "${container_mgr}" info | grep Root | grep -q /home; then
echo "Cannot build ISO with rootless container..."
exit 1
fi

# Get Inputs
image=$1
version=$2

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

# Set Container tag name
tag=$(just _tag "${image}")

# Remove old ISO if present
sudoif rm -f "${project_root}/just_scripts/output/${tag}-${version}-${git_branch}.iso"
sudoif rm -f "${project_root}/just_scripts/output/${tag}-${version}-${git_branch}.iso-CHECKSUM"

# Set variant
if [[ "${image}" =~ "silverblue" ]]; then
variant=Silverblue
else
variant=Kinoite
fi

if [[ ${container_mgr} =~ "podman" ]]; then
api_socket=/run/podman/podman.sock
elif [[ ${container_mgr} =~ "docker" ]]; then
api_socket=/var/run/docker.sock
fi

# Make sure image actually exists, build if it doesn't
ID=$(${container_mgr} images --filter reference=localhost/"${tag}:${version}-${git_branch}" --format "{{.ID}}")
if [[ -z ${ID} ]]; then
just build "${image}" "${version}"
fi

workspace=${project_root}
if [[ -f /.dockerenv || -f /run/.containerenv ]]; then
workspace=${LOCAL_WORKSPACE_FOLDER}
fi

# Make ISO
${container_mgr} run --rm --privileged \
--volume "${api_socket}":/var/run/docker.sock \
--volume "${workspace}"/just_scripts/build-iso-makefile-patch:/build-container-installer/container/Makefile \
--volume "${workspace}"/just_scripts/output:/build-container-installer/build \
ghcr.io/jasonn3/build-container-installer:main \
ARCH="x86_64" \
ENABLE_CACHE_DNF="false" \
ENABLE_CACHE_SKOPEO="false" \
ENROLLMENT_PASSWORD="ublue-os" \
IMAGE_NAME="${tag}" \
IMAGE_REPO="localhost" \
IMAGE_TAG="${version}-${git_branch}" \
ISO_NAME="build/${tag}-${version}-${git_branch}.iso" \
SECURE_BOOT_KEY_URL='https://github.com/ublue-os/akmods/raw/main/certs/public_key.der' \
VARIANT="${variant}" \
VERSION="${version}"
11 changes: 11 additions & 0 deletions just_scripts/build-iso-makefile-patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
$(IMAGE_NAME)-$(IMAGE_TAG):
skopeo copy docker-daemon:$(IMAGE_REPO)/$(IMAGE_NAME):$(IMAGE_TAG) oci:$(IMAGE_NAME)-$(IMAGE_TAG)

install-deps:
$(install_pkg) skopeo

FILES=$(filter-out Makefile,$(wildcard *))
clean:
ifneq ($(FILES),)
rm -Rf $(FILES)
endif
Loading
Loading