Skip to content

Commit ad83035

Browse files
committed
Added Cloudflared Support
Idea from https://github.com/zarti0 Thank you!
1 parent 8466fdb commit ad83035

File tree

6 files changed

+172
-56
lines changed

6 files changed

+172
-56
lines changed

.github/workflows/docker-image.yml

+4-17
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@ on:
55
- cron: '24 9 * * *'
66
push:
77
branches: [ "main" ]
8-
# Publish semver tags as releases.
98
tags: [ 'v*.*.*' ]
109
pull_request:
1110
branches: [ "main" ]
1211

1312
env:
14-
# Use docker.io for Docker Hub if empty
1513
REGISTRY: ghcr.io
16-
# github.repository as <account>/<repo>
1714
IMAGE_NAME: ${{ github.repository }}
1815

1916
jobs:
@@ -22,6 +19,7 @@ jobs:
2219
strategy:
2320
matrix:
2421
php-version: [ '8.0', '8.1', '8.2', '8.3', '8.4' ] # PHP versions to build
22+
architecture: [ 'amd64', 'arm64' ] # Add architecture matrix
2523

2624
permissions:
2725
contents: read
@@ -32,18 +30,9 @@ jobs:
3230
- name: Checkout repository
3331
uses: actions/checkout@v4
3432

35-
# Install the cosign tool except on PR
36-
- name: Install cosign
37-
if: github.event_name != 'pull_request'
38-
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0
39-
with:
40-
cosign-release: 'v2.2.4'
41-
42-
# Set up BuildKit Docker container builder
43-
- name: Set up Docker Buildx
33+
- name: Set up BuildKit Docker container builder
4434
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
4535

46-
# Login against a Docker registry except on PR
4736
- name: Log into registry ${{ env.REGISTRY }}
4837
if: github.event_name != 'pull_request'
4938
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
@@ -52,7 +41,6 @@ jobs:
5241
username: ${{ github.actor }}
5342
password: ${{ secrets.GITHUB_TOKEN }}
5443

55-
# Extract metadata (tags, labels) for Docker
5644
- name: Extract Docker metadata
5745
id: meta
5846
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
@@ -62,8 +50,7 @@ jobs:
6250
${{ matrix.php-version }}-${{ github.sha }}
6351
${{ matrix.php-version }}-latest
6452
${{ matrix.php-version }}
65-
66-
# Build and push Docker image with Buildx (don't push on PR)
53+
6754
- name: Build and push Docker image
6855
id: build-and-push
6956
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
@@ -77,8 +64,8 @@ jobs:
7764
cache-to: type=gha,mode=max
7865
build-args: |
7966
PHP_VERSION=${{ matrix.php-version }}
67+
ARCH=${{ matrix.architecture }} # Pass architecture to Dockerfile
8068
81-
# Sign the resulting Docker image digest except on PRs.
8269
- name: Sign the published Docker image
8370
if: ${{ github.event_name != 'pull_request' }}
8471
env:

Dockerfile

+16-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,26 @@ FROM debian:bookworm-slim
22

33
LABEL author="Ym0t" maintainer="[email protected]"
44

5-
ARG PHP_VERSION="8.3"
5+
ARG PHP_VERSION
66

77
ENV DEBIAN_FRONTEND noninteractive
88

99
RUN apt-get update \
10-
&& apt-get upgrade -y \
11-
&& apt-get install -y git apt-transport-https lsb-release ca-certificates wget nginx \
10+
&& apt-get install -y \
11+
git \
12+
apt-transport-https \
13+
lsb-release \
14+
ca-certificates \
15+
wget \
16+
nginx \
17+
&& ARCH=$(uname -m) \
18+
&& if [ "$ARCH" = "x86_64" ]; then \
19+
wget -O /tmp/cloudflared.deb https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb; \
20+
elif [ "$ARCH" = "aarch64" ]; then \
21+
wget -O /tmp/cloudflared.deb https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-arm64.deb; \
22+
fi \
23+
&& dpkg -i /tmp/cloudflared.deb \
24+
&& rm /tmp/cloudflared.deb \
1225
&& wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg \
1326
&& echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list \
1427
&& apt-get update \
@@ -71,7 +84,6 @@ RUN apt-get update \
7184
php${PHP_VERSION}-maxminddb \
7285
php${PHP_VERSION}-protobuf \
7386
php${PHP_VERSION}-OPcache \
74-
&& apt-get purge -y --auto-remove \
7587
&& rm -rf /var/lib/apt/lists/*
7688

7789
RUN useradd -m -d /home/container/ -s /bin/bash container

README.md

+52-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Pterodactyl Nginx egg
22

33
Nginx web server egg with PHP, optional Wordpress installation and git support.
4-
4+
<br><br>
55
## Features
66

77
#### Supports AMD64 & ARM64
@@ -14,7 +14,7 @@ Nginx web server egg with PHP, optional Wordpress installation and git support.
1414
- ☑️ 8.0 [EOL]
1515

1616
[PHP supported versions](https://www.php.net/supported-versions.php)
17-
17+
<br><br>
1818
## How to install
1919

2020
- **Step 1:** Download the egg (json file `egg-nginx.json`)
@@ -23,12 +23,58 @@ Nginx web server egg with PHP, optional Wordpress installation and git support.
2323
- **Step 4:** Create a new server and select the "Nginx" egg
2424
- **Step 5:** Select the corresponding Docker image with the desired PHP version
2525
- **Step 6:** Fill in the text fields. Whether Wordpress is desired or not. It is important to **enter the selected PHP version in the PHP version field**.
26+
<br><br>
27+
## 🚀 Cloudflared Tunnel Tutorial
28+
29+
With **Cloudflared**, you can create a secure tunnel to your server, making it accessible over the internet **without** complicated port forwarding!
30+
[Cloudflared | Create a remotely-managed tunnel](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/get-started/create-remote-tunnel/)
31+
32+
### 📌 Requirements
33+
- A [Cloudflare](https://dash.cloudflare.com/) account
34+
- A domain (optional but recommended)
35+
36+
---
37+
38+
- 🔹 **Step 1: Log in to Zero Trust ↗ and go to Networks > Tunnel**
39+
- 🔹 **Step 2: Select Create a tunnel.**
40+
- 🔹 **Step 3: Choose Cloudflared for the connector type and select Next.**
41+
- 🔹 **Step 4: Enter a name for your tunnel.**
42+
- 🔹 **Step 5: Select Save tunnel.**
43+
- 🔹 **Step 6: Save the token. (The token is very long)**
44+
45+
![grafik](https://github.com/user-attachments/assets/0c0430a5-5cb6-45e4-8b26-1805cddde3cc)
46+
47+
48+
---
49+
50+
- 🔹 **Step 7: Activate Cloudflared**
51+
52+
![grafik](https://github.com/user-attachments/assets/726c5dad-7cb6-4537-a215-6aaec59d827a)
53+
54+
55+
---
56+
57+
- 🔹 **Step 8: Add your token.**
58+
59+
![grafik](https://github.com/user-attachments/assets/46b09f6a-30b0-48aa-9980-53697b1fbcf6)
2660

61+
62+
---
63+
64+
- 🔹 **Step 9: Restart your webserver.**
65+
66+
![grafik](https://github.com/user-attachments/assets/84fb9b6c-10cd-4bd3-86ae-e725e7145e8d)
67+
68+
---
69+
70+
✅ You have successfully set up Cloudflared and connected it to your server!
71+
<br><br>
2772
## FAQ
2873

74+
2975
#### In which folder do I upload my files for my site?
3076
The "www" folder is used as a public folder. There you can add your PHP, HTML, CSS, JS and so on files that are required for the public or for the operation of the site.
31-
77+
<br><br>
3278
## How do I use Git support?
3379

3480
#### Instructions for Git support
@@ -83,7 +129,7 @@ Furthermore, if not already done, adjust to your domain:
83129
```bash
84130
server_name www.example.com;
85131
```
86-
132+
<br><br>
87133
## Change PHP version
88134

89135
Changing the PHP version is currently still somewhat cumbersome. A revised version will be available in the future.
@@ -101,7 +147,7 @@ Changing the PHP version is currently still somewhat cumbersome. A revised versi
101147
---
102148

103149
- **Step 3:** Restart your container.
104-
150+
<br><br>
105151
## PHP extensions
106152

107153
PHP extensions of PHP version 8.3:
@@ -111,7 +157,7 @@ Core, date, libxml, openssl, pcre, zlib, filter, hash, json, random, Reflection,
111157
```
112158

113159
Small differences in the extensions between the PHP versions.
114-
160+
<br><br>
115161
## License
116162

117163
[MIT License](https://choosealicense.com/licenses/mit/)

cloudflared.sh

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
# [Tunnel] Check if cloudflared_token.txt exists and has content
4+
if [ -s "/home/container/cloudflared_token.txt" ]; then
5+
# If the file has content, start cloudflared using the content as the token
6+
echo "[Tunnel] Starting cloudflared tunnel with token"
7+
cloudflared tunnel --no-autoupdate run --token "$(cat /home/container/cloudflared_token.txt)" > /dev/null 2>&1 &
8+
9+
# Wait for the tunnel to start
10+
echo "[Tunnel] Waiting for cloudflared tunnel to start..."
11+
12+
# Set max number of attempts
13+
MAX_ATTEMPTS=10
14+
ATTEMPT=0
15+
16+
# Check if cloudflared is running, repeat every 1 second until it is or max attempts reached
17+
while ! pgrep -x "cloudflared" > /dev/null && [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
18+
ATTEMPT=$((ATTEMPT + 1))
19+
sleep 1
20+
done
21+
22+
# If cloudflared is running
23+
if pgrep -x "cloudflared" > /dev/null; then
24+
# Green success message
25+
echo -e "[Tunnel]\033[0;32m Cloudflared tunnel is running successfully.\033[0m"
26+
else
27+
echo -e "[Tunnel]\033[0;31m Failed to start cloudflared tunnel after $MAX_ATTEMPTS attempts. Exiting...\033[0m"
28+
exit 1
29+
fi
30+
31+
else
32+
echo "[Tunnel]\033[0;31m cloudflared_token.txt is empty or does not exist. Skipping cloudflared startup.\033[0m"
33+
fi

0 commit comments

Comments
 (0)