From e3c5d6222d2e50a93f0a5bb93fac2273b8c0f5fd Mon Sep 17 00:00:00 2001 From: Stuart Leeks Date: Sat, 9 May 2026 09:23:03 +0000 Subject: [PATCH] Add railway-cli feature --- src/railway-cli/NOTES.md | 6 +++ src/railway-cli/README.md | 31 +++++++++++++ src/railway-cli/devcontainer-feature.json | 17 +++++++ src/railway-cli/install.sh | 37 +++++++++++++++ src/railway-cli/oncreate.sh | 53 ++++++++++++++++++++++ test/railway-cli/base.sh | 17 +++++++ test/railway-cli/scenarios.json | 8 ++++ test/railway-cli/test.sh | 55 +++++++++++++++++++++++ 8 files changed, 224 insertions(+) create mode 100644 src/railway-cli/NOTES.md create mode 100644 src/railway-cli/README.md create mode 100644 src/railway-cli/devcontainer-feature.json create mode 100644 src/railway-cli/install.sh create mode 100644 src/railway-cli/oncreate.sh create mode 100644 test/railway-cli/base.sh create mode 100644 test/railway-cli/scenarios.json create mode 100644 test/railway-cli/test.sh diff --git a/src/railway-cli/NOTES.md b/src/railway-cli/NOTES.md new file mode 100644 index 0000000..a7b7184 --- /dev/null +++ b/src/railway-cli/NOTES.md @@ -0,0 +1,6 @@ + +## Changelog + +| Version | Notes | +| ------- | ------------------------------------------------------------------- | +| 0.0.1 | Initial version | \ No newline at end of file diff --git a/src/railway-cli/README.md b/src/railway-cli/README.md new file mode 100644 index 0000000..c4e2f29 --- /dev/null +++ b/src/railway-cli/README.md @@ -0,0 +1,31 @@ + +# Dev Tunnels (dev-tunnels) + +Set up the `devtunnel` CLI for working with [Dev Tunnels](https://learn.microsoft.com/en-us/azure/developer/dev-tunnels/overview) + +## Example Usage + +```json +"features": { + "ghcr.io/stuartleeks/dev-container-features/dev-tunnels:0": {} +} +``` + +## Options + +| Options Id | Description | Type | Default Value | +|-----|-----|-----|-----| + + + +## Changelog + +| Version | Notes | +| ------- | ------------------------------------------------------------------- | +| 0.0.3 | Set `HISTFILE_OLD` when replacing a previous `HSITFILE` value | +| 0.0.2 | Initial work to reduce the requirement on `sudo` in `shell-history` | +| 0.0.1 | Initial version | + +--- + +_Note: This file was auto-generated from the [devcontainer-feature.json](https://github.com/stuartleeks/dev-container-features/blob/main/src/dev-tunnels/devcontainer-feature.json). Add additional notes to a `NOTES.md`._ diff --git a/src/railway-cli/devcontainer-feature.json b/src/railway-cli/devcontainer-feature.json new file mode 100644 index 0000000..8f6a932 --- /dev/null +++ b/src/railway-cli/devcontainer-feature.json @@ -0,0 +1,17 @@ +{ + "name": "Railway CLI", + "id": "railway-cli", + "version": "0.0.1", + "description": "Set up the `railway` CLI for working with [Railway](https://railway.com/)", + "options": {}, + "mounts": [ + { + "source": "${devcontainerId}-railway-cli", + "target": "/dc/railway-cli", + "type": "volume" + } + ], + "onCreateCommand": { + "railway-cli": "/usr/local/share/stuartleeks-devcontainer-features/railway-cli/scripts/oncreate.sh" + } +} \ No newline at end of file diff --git a/src/railway-cli/install.sh b/src/railway-cli/install.sh new file mode 100644 index 0000000..a27b413 --- /dev/null +++ b/src/railway-cli/install.sh @@ -0,0 +1,37 @@ +#!/bin/sh +FEATURE_DIR="/usr/local/share/stuartleeks-devcontainer-features/railway-cli" +LIFECYCLE_SCRIPTS_DIR="$FEATURE_DIR/scripts" +LOG_FILE="$FEATURE_DIR/log.txt" + +set -e + +mkdir -p "${FEATURE_DIR}" + +echo "" > "$LOG_FILE" +log() { + echo "$1" + echo "$1" >> "$LOG_FILE" +} + +log "Activating feature 'railway-cli'" +log "User: ${_REMOTE_USER} User home: ${_REMOTE_USER_HOME}" + +# Set up symlink for .railway folder to persistent volume +got_old_railway_folder=false +if [ -e "$_REMOTE_USER_HOME/.railway" ]; then + log "Moving existing .railway folder to .railway-old" + mv "$_REMOTE_USER_HOME/.railway" "$_REMOTE_USER_HOME/.railway-old" + got_old_railway_folder=true +else + log "No existing .railway folder found at '$_REMOTE_USER_HOME/.railway'" +fi + +ln -s /dc/railway-cli/ "$_REMOTE_USER_HOME/.railway" +chown -R "${_REMOTE_USER}:${_REMOTE_USER}" "$_REMOTE_USER_HOME/.railway" +log "Symlink created for .railway folder to /dc/railway-cli/" + +# Defer installation to oncreate script +# This allows fixing up the /dc/railway-cli/ folder permissions before the CLI is installed and creates files in that folder +mkdir -p "${LIFECYCLE_SCRIPTS_DIR}" +cp oncreate.sh "${LIFECYCLE_SCRIPTS_DIR}/oncreate.sh" + diff --git a/src/railway-cli/oncreate.sh b/src/railway-cli/oncreate.sh new file mode 100644 index 0000000..8f33e33 --- /dev/null +++ b/src/railway-cli/oncreate.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +set -e + + +FEATURE_DIR="/usr/local/share/stuartleeks-devcontainer-features/railway-cli" +LOG_FILE="$FEATURE_DIR/log.txt" + +log() { + echo "$1" + echo "$1" >> "$LOG_FILE" +} + +if command -v sudo > /dev/null; then + sudo chown -R "$(id -u):$(id -g)" "$LOG_FILE" +else + chown -R "$(id -u):$(id -g)" "$LOG_FILE" +fi + +log "In OnCreate script" + + +fix_permissions() { + local dir + dir="${1}" + + if [ ! -w "${dir}" ]; then + log "Fixing permissions of '${dir}'..." + sudo chown -R "$(id -u):$(id -g)" "${dir}" + log "Done!" + else + log "Permissions of '${dir}' are OK!" + fi +} + +fix_permissions "/dc/railway-cli" + +# Docs: https://docs.railway.com/cli +# Run the install as the remote user +log "Installing railway CLI and agents" +bash <(curl -fsSL railway.com/install.sh) --agents -y + +# Set up bash completion for the railway CLI +log "Setting up bash completion for railway CLI" +echo 'source <(railway completion bash)' >> ~/.bashrc + + +# TODO +# - Add option for installing the CLI without agents +# - Add option for disabling telemetry + +log "Done" + diff --git a/test/railway-cli/base.sh b/test/railway-cli/base.sh new file mode 100644 index 0000000..479fd4a --- /dev/null +++ b/test/railway-cli/base.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -e + +# Optional: Import test library bundled with the devcontainer CLI +# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib +# Provides the 'check' and 'reportResults' commands. +source dev-container-features-test-lib + +# Feature-specific tests +# The 'check' command comes from the dev-container-features-test-lib. Syntax is... +# check