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

Add a feature that installs dependencies from an Aptfile.dev file #1136

Closed
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
5 changes: 5 additions & 0 deletions src/apt/NOTES.md
Original file line number Diff line number Diff line change
@@ -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.
42 changes: 42 additions & 0 deletions src/apt/README.md
Original file line number Diff line number Diff line change
@@ -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
```
16 changes: 16 additions & 0 deletions src/apt/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
22 changes: 22 additions & 0 deletions src/apt/install.sh
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions test/apt/install_ffmpeg.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test/apt/install_ffmpeg/Aptfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ffmpeg
5 changes: 5 additions & 0 deletions test/apt/install_ffmpeg/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions test/apt/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"install_ffmpeg": {
"build": {
"dockerfile": "Dockerfile"
},
"remoteUser": "vscode",
"features": {
"apt": {
"version": "1",
"devFile": "Aptfile.dev"
}
}
}
}
3 changes: 3 additions & 0 deletions test/apt/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

set -e