Skip to content

Commit e508ee0

Browse files
added fly cli
1 parent f760901 commit e508ee0

3 files changed

Lines changed: 101 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "Concourse Fly CLI",
3+
"id": "fly-cli",
4+
"version": "1.0.0",
5+
"description": "Installs the Concourse Fly CLI.",
6+
"options": {
7+
"url": {
8+
"type": "string",
9+
"description": "Concourse URL to download the Fly CLI from"
10+
}
11+
},
12+
"installsAfter": [
13+
"ghcr.io/devcontainers/features/common-utils"
14+
]
15+
}

src/fly-cli/install.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env bash
2+
3+
: ${URL:=https://ci.nulldriver.com}
4+
5+
USERNAME=${USERNAME:-${_REMOTE_USER:-"automatic"}}
6+
7+
set -e
8+
9+
export TMPDIR=$(mktemp -d /tmp/feature.XXXXXX)
10+
trap "rm -rf $TMPDIR" EXIT
11+
12+
# Clean up
13+
rm -rf /var/lib/apt/lists/*
14+
15+
if [ "$(id -u)" -ne 0 ]; then
16+
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
17+
exit 1
18+
fi
19+
20+
architecture="$(dpkg --print-architecture)"
21+
if [ "${architecture}" != "amd64" ] && [ "${architecture}" != "arm64" ]; then
22+
echo "(!) Architecture $architecture unsupported"
23+
exit 1
24+
fi
25+
26+
# Determine the appropriate non-root user
27+
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
28+
USERNAME=""
29+
POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)")
30+
for CURRENT_USER in "${POSSIBLE_USERS[@]}"; do
31+
if id -u "${CURRENT_USER}" >/dev/null 2>&1; then
32+
USERNAME=${CURRENT_USER}
33+
break
34+
fi
35+
done
36+
if [ "${USERNAME}" = "" ]; then
37+
USERNAME=root
38+
fi
39+
elif [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} >/dev/null 2>&1; then
40+
USERNAME=root
41+
fi
42+
43+
apt_get_update() {
44+
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
45+
echo "Running apt-get update..."
46+
apt-get update -y
47+
fi
48+
}
49+
50+
# Checks if packages are installed and installs them if not
51+
check_packages() {
52+
if ! dpkg -s "$@" >/dev/null 2>&1; then
53+
apt_get_update
54+
apt-get -y install --no-install-recommends "$@"
55+
fi
56+
}
57+
58+
export DEBIAN_FRONTEND=noninteractive
59+
60+
### BEGIN install
61+
62+
# Soft version matching
63+
check_packages curl ca-certificates
64+
echo "Downloading fly..."
65+
curl -SL "$URL/api/v1/cli?arch=amd64&platform=linux" -o "$TMPDIR/fly"
66+
install "$TMPDIR/fly" /usr/local/bin/fly
67+
68+
### END install
69+
70+
# Clean up
71+
rm -rf /var/lib/apt/lists/*
72+
73+
echo "Done!"

test/fly-cli/test.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
# This test can be run with the following command (from the root of this repo)
4+
# devcontainer features test --features fly-cli --base-image mcr.microsoft.com/devcontainers/base:ubuntu .
5+
6+
set -e
7+
8+
# Import 'check' command
9+
source dev-container-features-test-lib
10+
11+
check "version" fly -version
12+
13+
reportResults

0 commit comments

Comments
 (0)