Skip to content
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
6 changes: 6 additions & 0 deletions src/railway-cli/NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

## Changelog

| Version | Notes |
| ------- | ------------------------------------------------------------------- |
| 0.0.1 | Initial version |
31 changes: 31 additions & 0 deletions src/railway-cli/README.md
Original file line number Diff line number Diff line change
@@ -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`._
17 changes: 17 additions & 0 deletions src/railway-cli/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
37 changes: 37 additions & 0 deletions src/railway-cli/install.sh
Original file line number Diff line number Diff line change
@@ -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"

53 changes: 53 additions & 0 deletions src/railway-cli/oncreate.sh
Original file line number Diff line number Diff line change
@@ -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"

17 changes: 17 additions & 0 deletions test/railway-cli/base.sh
Original file line number Diff line number Diff line change
@@ -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 <LABEL> <cmd> [args...]

check "Check railway is installed" bash -c "railway --version" | grep 'railway'

# Report result
# If any of the checks above exited with a non-zero exit code, the test will fail.
reportResults
8 changes: 8 additions & 0 deletions test/railway-cli/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"base": {
"image": "mcr.microsoft.com/devcontainers/base:debian",
"features": {
"railway-cli": {}
}
}
}
55 changes: 55 additions & 0 deletions test/railway-cli/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash
set -e

# This test file will be executed against an auto-generated devcontainer.json that
# includes the 'color' Feature with no options.
#
# For more information, see: https://github.com/devcontainers/cli/blob/main/docs/features/test.md
#
# Eg:
# {
# "image": "<..some-base-image...>",
# "features": {
# "color": {}
# },
# "remoteUser": "root"
# }
#
# Thus, the value of all options will fall back to the default value in the
# Feature's 'devcontainer-feature.json'.
# For the 'color' feature, that means the default favorite color is 'red'.
#
# These scripts are run as 'root' by default. Although that can be changed
# with the '--remote-user' flag.
#
# This test can be run with the following command:
#
# devcontainer features test \
# --features color \
# --remote-user root \
# --skip-scenarios \
# --base-image mcr.microsoft.com/devcontainers/base:ubuntu \
# /path/to/this/repo


# 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 <LABEL> <cmd> [args...]

# NOTE: currently have to run the test using zsh as the devtunnel install script only adds the PATH to the first shell config it finds
# and when running as root in the dev container base image used for testing, that is .zshrc
# check "Check devtunnel is installed" zsh --interactive -c "devtunnel --version" | grep 'Tunnel CLI'

## TODO - Update the following to not use the path (i.e. fix up the installation!)

check "Check railway is installed" bash -c "railway --version" | grep 'railway'

# Report result
# If any of the checks above exited with a non-zero exit code, the test will fail.
reportResults

Loading