diff --git a/src/apt/NOTES.md b/src/apt/NOTES.md new file mode 100644 index 000000000..001162a8f --- /dev/null +++ b/src/apt/NOTES.md @@ -0,0 +1,5 @@ +# OS Support + +This feature supports recent versions of Debian and Ubuntu distributions with the `apt` package manager. It works with any base image using these distributions, like `ubuntu:focal` or `debian:buster`. + +`bash` is required to execute the `install.sh` script. diff --git a/src/apt/README.md b/src/apt/README.md new file mode 100644 index 000000000..0b6f46bf5 --- /dev/null +++ b/src/apt/README.md @@ -0,0 +1,42 @@ +# Aptfile Dependencies (apt) + +Install apt dependencies defined in an `Aptfile.dev` file. This feature is inspired by the approach found in [heroku-buildpack-apt](https://github.com/heroku/heroku-buildpack-apt) and [Aptfile Buildpack on App Platform](https://docs.digitalocean.com/products/app-platform/reference/buildpacks/aptfile/). It simplifies the process of managing and installing apt packages required for a development environment by specifying them in one file. + +## Example Usage + +```json +"features": { + "ghcr.io/viktorianer/features/apt:1": { + "devFile": "../Aptfile.dev" + } +} +``` + +## Options + +| Options Id | Description | Type | Default Value | +|------------|-------------|--------|---------------| +| devFile | Path to the Aptfile.dev file. This is where the list of apt packages is defined. | string | `../Aptfile.dev` | + +## How It Works + +- The feature reads the list of packages from the `Aptfile.dev` file and installs them during the container setup. +- The default path is `Aptfile.dev`, but this can be customized using the `devFile` option. +- It removes any commented or empty lines before installing the packages with `apt-get install`. + +Example `Aptfile.dev`: + +```bash +# Video thumbnails +ffmpeg +libvips + +# PDF thumbnails +poppler-utils +# mupdf +# mupdf-tools + +# PostgreSQL +libpq-dev +postgresql-client +``` diff --git a/src/apt/devcontainer-feature.json b/src/apt/devcontainer-feature.json new file mode 100644 index 000000000..062a0afa9 --- /dev/null +++ b/src/apt/devcontainer-feature.json @@ -0,0 +1,16 @@ +{ + "id": "apt", + "version": "1.0.0", + "name": "Aptfile Dependencies", + "description": "Installs apt dependencies defined in an Aptfile.dev file.", + "options": { + "devFile": { + "type": "string", + "description": "Optional custom Aptfile.dev path", + "default": "../Aptfile.dev" + } + }, + "installsAfter": [ + "ghcr.io/devcontainers/features/common-utils" + ] +} diff --git a/src/apt/install.sh b/src/apt/install.sh new file mode 100755 index 000000000..2a047a8b4 --- /dev/null +++ b/src/apt/install.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -e + +# Exit script if any command fails +set -o errexit + +# Debugging (optional, comment out if not needed) +# set -x + +# Use the DEVFILE environment variable to find the Aptfile.dev +if [ -f "$DEVFILE" ]; then + echo "Aptfile.dev detected at $DEVFILE. Installing dependencies..." + + apt-get update -y + grep -Ev "^\s*#" "$DEVFILE" | xargs apt-get install --no-install-recommends -y + rm -rf /var/lib/apt/lists/* + + echo "Dependencies from $DEVFILE have been installed." +else + echo "No Aptfile.dev found at $DEVFILE, skipping apt dependencies installation." +fi diff --git a/test/apt/install_ffmpeg.sh b/test/apt/install_ffmpeg.sh new file mode 100755 index 000000000..dcb46f780 --- /dev/null +++ b/test/apt/install_ffmpeg.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +# Definition specific tests +check "ffmpeg" ffmpeg -version + +# Report result +reportResults diff --git a/test/apt/install_ffmpeg/Aptfile.dev b/test/apt/install_ffmpeg/Aptfile.dev new file mode 100644 index 000000000..20645e641 --- /dev/null +++ b/test/apt/install_ffmpeg/Aptfile.dev @@ -0,0 +1 @@ +ffmpeg diff --git a/test/apt/install_ffmpeg/Dockerfile b/test/apt/install_ffmpeg/Dockerfile new file mode 100644 index 000000000..db804f8e6 --- /dev/null +++ b/test/apt/install_ffmpeg/Dockerfile @@ -0,0 +1,5 @@ +# Builds an image with a preconfigured SUDOERS file +# Used to test the install script for JupyterLab which modifies this file +FROM mcr.microsoft.com/devcontainers/base:debian + +COPY --chown=vscode Aptfile.dev /tmp/dev-container-features/apt_0/Aptfile.dev diff --git a/test/apt/scenarios.json b/test/apt/scenarios.json new file mode 100644 index 000000000..f65b02495 --- /dev/null +++ b/test/apt/scenarios.json @@ -0,0 +1,14 @@ +{ + "install_ffmpeg": { + "build": { + "dockerfile": "Dockerfile" + }, + "remoteUser": "vscode", + "features": { + "apt": { + "version": "1", + "devFile": "Aptfile.dev" + } + } + } +} diff --git a/test/apt/test.sh b/test/apt/test.sh new file mode 100644 index 000000000..df82332cd --- /dev/null +++ b/test/apt/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +set -e