Skip to content

Commit accefb3

Browse files
committed
🛠️ Update nginx feature
1 parent 8bf4d33 commit accefb3

File tree

2 files changed

+14
-26
lines changed

2 files changed

+14
-26
lines changed

features/nginx/devcontainer-feature.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"options": {
77
"version": {
88
"type": "string",
9-
"default": "1.26.3-1~focal",
10-
"description": "Version of the Nginx to install"
9+
"default": "latest",
10+
"description": "Version of the Nginx to install. Use 'latest' for the default version or specific version like '1.26.3-1~noble'"
1111
}
1212
}
1313
}

features/nginx/install.sh

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,30 @@
22

33
set -e
44

5-
# Read version from the environment variable (set by devcontainer feature)
5+
# Read version from the environment variable
66
NGINX_VERSION="${VERSION:-latest}"
77

8-
# Update package list and install dependencies
9-
apt-get update && apt-get install -y curl gnupg2 software-properties-common ca-certificates
10-
11-
# Add repository
12-
echo "deb http://nginx.org/packages/ubuntu/ focal nginx
13-
deb-src http://nginx.org/packages/ubuntu/ focal nginx" | tee /etc/apt/sources.list.d/nginx.list
14-
15-
# Add GPG key
16-
curl -fsSL https://nginx.org/keys/nginx_signing.key | apt-key add -
17-
18-
# Update package list again
8+
# Update package list
199
apt-get update
2010

21-
# Check available versions
22-
AVAILABLE_VERSIONS=$(apt-cache madison nginx | awk '{print $3}')
23-
24-
# Install Nginx with the specified version
11+
# Install Nginx
2512
if [ "$NGINX_VERSION" = "latest" ]; then
26-
echo "Installing latest available Nginx version..."
13+
echo "Installing Nginx..."
2714
apt-get install -y nginx
2815
else
29-
if echo "$AVAILABLE_VERSIONS" | grep -q "^$NGINX_VERSION$"; then
30-
echo "Installing Nginx version $NGINX_VERSION..."
31-
apt-get install -y nginx=$NGINX_VERSION*
16+
echo "Installing Nginx version $NGINX_VERSION..."
17+
if apt-cache show "nginx=$NGINX_VERSION" >/dev/null 2>&1; then
18+
apt-get install -y "nginx=$NGINX_VERSION"
3219
else
33-
echo "Error: Nginx version $NGINX_VERSION is not available in APT repositories."
34-
echo "Available versions: $AVAILABLE_VERSIONS"
35-
exit 1
20+
echo "Requested version $NGINX_VERSION not available. Installing latest version."
21+
apt-get install -y nginx
3622
fi
3723
fi
3824

3925
# Start Nginx
4026
service nginx start || nginx
4127

4228
# Verify installation
43-
nginx -v
29+
nginx -v
30+
31+
echo "Nginx installation completed."

0 commit comments

Comments
 (0)