Skip to content

Commit 95264d5

Browse files
authored
Merge pull request #19 from kool-dev/restructure
Restructure
2 parents 45c495f + ee33ef1 commit 95264d5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1936
-208
lines changed

.github/workflows/ci-cd.yml

+44-36
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,69 @@ name: CI/CD
33
on:
44
push:
55
workflow_dispatch:
6-
schedule:
7-
- cron: '0 0 * * 0'
8-
9-
env:
10-
DOCKER_BUILDKIT: 1
116

127
jobs:
138
build:
14-
name: Build
159
runs-on: ubuntu-latest
10+
11+
services:
12+
registry:
13+
image: registry:2
14+
ports:
15+
- 5000:5000
16+
1617
strategy:
1718
matrix:
18-
version: ['8.0', '8.1', '8.2', '8.3']
19-
type: ['-swoole', '-nginx-swoole-prod']
19+
version: ['8.0-swoole', '8.1-swoole', '8.2-swoole', '8.3-swoole']
20+
type: ['', '-prod']
2021

2122
steps:
2223
- name: Checkout code
23-
uses: actions/[email protected].1
24+
uses: actions/[email protected].2
2425

2526
- name: Setup QEMU
2627
uses: docker/setup-qemu-action@v3
2728

2829
- name: Setup Docker Buildx
2930
uses: docker/setup-buildx-action@v3
30-
31-
- name: Login to DockerHub
32-
uses: docker/login-action@v3
33-
if: github.ref == 'refs/heads/main' && github.repository == 'kool-dev/docker-php-swoole'
3431
with:
35-
username: ${{ secrets.DOCKER_USERNAME }}
36-
password: ${{ secrets.DOCKER_PASSWORD }}
32+
driver-opts: network=host # needed to push to local registry
3733

3834
- name: Build and export to Docker
3935
uses: docker/build-push-action@v5
4036
with:
4137
context: ${{ matrix.version }}${{ matrix.type }}
42-
load: true
43-
tags: kooldev/php:${{ matrix.version }}${{ matrix.type }}
38+
push: true
39+
tags: localhost:5000/kooldev/php:${{ matrix.version }}${{ matrix.type }}
4440

45-
- name: Tests (dev)
46-
if: matrix.type == '-swoole'
41+
- name: Build and export to Docker (nginx)
42+
uses: docker/build-push-action@v5
43+
with:
44+
context: ${{ matrix.version }}-nginx${{ matrix.type }}
45+
push: true
46+
tags: localhost:5000/kooldev/php:${{ matrix.version }}-nginx${{ matrix.type }}
47+
build-contexts: |
48+
kooldev/php:${{ matrix.version }}${{ matrix.type }}=docker-image://localhost:5000/kooldev/php:${{ matrix.version }}${{ matrix.type }}
49+
50+
- name: Tests
4751
run: |
48-
docker run kooldev/php:${{ matrix.version }}${{ matrix.type }} php -r "extension_loaded('swoole') or die(1);"
49-
docker run kooldev/php:${{ matrix.version }}${{ matrix.type }} node -v
50-
docker run kooldev/php:${{ matrix.version }}${{ matrix.type }} yarn -v
52+
docker run localhost:5000/kooldev/php:${{ matrix.version }}${{ matrix.type }} php -r "extension_loaded('swoole') or die(1);"
53+
docker run localhost:5000/kooldev/php:${{ matrix.version }}-nginx${{ matrix.type }} nginx -v
5154
52-
- name: Tests (prod)
53-
if: matrix.type == '-nginx-swoole-prod'
55+
- name: Tests (dev)
56+
if: matrix.type == ''
5457
run: |
55-
docker run kooldev/php:${{ matrix.version }}${{ matrix.type }} php -r "extension_loaded('swoole') or die(1);"
56-
docker run kooldev/php:${{ matrix.version }}${{ matrix.type }} nginx -v
58+
docker run localhost:5000/kooldev/php:${{ matrix.version }}${{ matrix.type }} node -v
59+
docker run localhost:5000/kooldev/php:${{ matrix.version }}${{ matrix.type }} yarn -v
60+
docker run localhost:5000/kooldev/php:${{ matrix.version }}-nginx${{ matrix.type }} node -v
61+
docker run localhost:5000/kooldev/php:${{ matrix.version }}-nginx${{ matrix.type }} yarn -v
62+
63+
- name: Login to DockerHub
64+
uses: docker/login-action@v3
65+
if: github.ref == 'refs/heads/main' && github.repository == 'kool-dev/docker-php-swoole'
66+
with:
67+
username: ${{ secrets.DOCKER_USERNAME }}
68+
password: ${{ secrets.DOCKER_PASSWORD }}
5769

5870
- name: Build and push
5971
uses: docker/build-push-action@v5
@@ -64,15 +76,11 @@ jobs:
6476
push: true
6577
tags: kooldev/php:${{ matrix.version }}${{ matrix.type }}
6678

67-
trigger-build-oci8:
68-
name: Trigger OCI8 Build
69-
runs-on: ubuntu-latest
70-
needs: build
71-
steps:
72-
- name: Trigger build on kool-dev/docker-php-oci8
73-
uses: benc-uk/[email protected]
79+
- name: Build and push (nginx)
80+
uses: docker/build-push-action@v5
7481
if: github.ref == 'refs/heads/main' && github.repository == 'kool-dev/docker-php-swoole'
7582
with:
76-
workflow: CI/CD
77-
repo: kool-dev/docker-php-oci8
78-
token: ${{ secrets.WORKFLOW_TOKEN }}
83+
context: ${{ matrix.version }}-nginx${{ matrix.type }}
84+
platforms: linux/amd64,linux/arm64
85+
push: true
86+
tags: kooldev/php:${{ matrix.version }}-nginx${{ matrix.type }}

8.0-nginx-swoole-prod/Dockerfile

-19
This file was deleted.

8.0-swoole-nginx-prod/Dockerfile

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
FROM debian AS cert
2+
3+
WORKDIR /kool/ssl
4+
5+
RUN apt-get update && \
6+
apt-get install -y openssl && \
7+
openssl genrsa -des3 -passout pass:x -out server.pass.key 2048 && \
8+
openssl rsa -passin pass:x -in server.pass.key -out _.localhost.key && \
9+
rm server.pass.key && \
10+
openssl req -new -key _.localhost.key -out server.csr \
11+
-subj "/C=XX/ST=XX/L=XX/O=Kool-Local/OU=Localhost/CN=*.localhost" && \
12+
openssl x509 -req -days 365 -in server.csr -signkey _.localhost.key -out _.localhost.crt && \
13+
openssl x509 -in _.localhost.crt -out _.localhost.pem
14+
15+
FROM kooldev/php:8.0-swoole-prod
16+
17+
ENV PHP_FPM_LISTEN=/run/php-fpm.sock \
18+
NGINX_LISTEN=80 \
19+
NGINX_HTTPS=false \
20+
NGINX_LISTEN_HTTPS=443 \
21+
NGINX_HTTPS_CERT=/kool/ssl/_.localhost.pem \
22+
NGINX_HTTPS_CERT_KEY=/kool/ssl/_.localhost.key \
23+
NGINX_ROOT=/app/public \
24+
NGINX_INDEX=index.php \
25+
NGINX_CLIENT_MAX_BODY_SIZE=25M \
26+
NGINX_PHP_FPM=unix:/run/php-fpm.sock \
27+
NGINX_FASTCGI_READ_TIMEOUT=60s \
28+
NGINX_FASTCGI_BUFFERS='8 8k' \
29+
NGINX_FASTCGI_BUFFER_SIZE='16k' \
30+
NGINX_ENTRYPOINT_WORKER_PROCESSES_AUTOTUNE=true
31+
32+
RUN curl -L https://github.com/ochinchina/supervisord/releases/download/v0.6.3/supervisord_static_0.6.3_linux_amd64 -o /usr/local/bin/supervisord \
33+
&& chmod +x /usr/local/bin/supervisord \
34+
&& apk add --no-cache nginx \
35+
&& chown -R kool:kool /var/lib/nginx \
36+
&& chmod 770 /var/lib/nginx/tmp \
37+
&& ln -sf /dev/stdout /var/log/nginx/access.log \
38+
&& ln -sf /dev/stderr /var/log/nginx/error.log \
39+
# add h5bp/server-configs-nginx
40+
&& mkdir -p /etc/nginx/conf.d \
41+
&& mkdir /etc/nginx/h5bp \
42+
&& cd /etc/nginx/h5bp \
43+
&& wget https://github.com/h5bp/server-configs-nginx/archive/refs/tags/3.3.0.tar.gz -O h5bp.tgz \
44+
&& tar xzvf h5bp.tgz \
45+
&& rm -f h5bp.tgz \
46+
&& mv server-configs-nginx-*/h5bp/* . \
47+
&& mv server-configs-nginx-*/nginx.conf /etc/nginx/nginx.conf \
48+
&& sed -i "s|^user .*|user\ kool kool;|g" /etc/nginx/nginx.conf \
49+
&& mv server-configs-nginx-*/mime.types /etc/nginx/mime.types \
50+
&& rm -rf server-configs-nginx-* \
51+
&& curl -L https://raw.githubusercontent.com/nginxinc/docker-nginx/master/entrypoint/30-tune-worker-processes.sh -o /kool/30-tune-worker-processes.sh \
52+
&& chmod +x /kool/30-tune-worker-processes.sh
53+
54+
COPY supervisor.conf /kool/supervisor.conf
55+
COPY default.tmpl /kool/default.tmpl
56+
COPY entrypoint /kool/entrypoint
57+
COPY --from=cert /kool/ssl /kool/ssl
58+
RUN chmod +x /kool/entrypoint
59+
60+
EXPOSE 80
61+
62+
CMD [ "supervisord", "-c", "/kool/supervisor.conf" ]

8.0-swoole-nginx-prod/default.tmpl

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
map $http_upgrade $connection_upgrade {
2+
default upgrade;
3+
'' close;
4+
}
5+
6+
server {
7+
listen {{ .Env.NGINX_LISTEN }} default_server;
8+
server_name _;
9+
{{ if isTrue .Env.NGINX_HTTPS }}
10+
listen {{ .Env.NGINX_LISTEN_HTTPS }} ssl http2;
11+
ssl_certificate {{ .Env.NGINX_HTTPS_CERT }};
12+
ssl_certificate_key {{ .Env.NGINX_HTTPS_CERT_KEY }};
13+
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
14+
ssl_ciphers HIGH:!aNULL:!MD5;
15+
{{ end }}
16+
root {{ .Env.NGINX_ROOT }};
17+
index {{ .Env.NGINX_INDEX }};
18+
charset utf-8;
19+
20+
location = /favicon.ico { log_not_found off; access_log off; }
21+
location = /robots.txt { log_not_found off; access_log off; }
22+
23+
client_max_body_size {{ .Env.NGINX_CLIENT_MAX_BODY_SIZE }};
24+
25+
error_page 404 /index.php;
26+
27+
location /index.php {
28+
try_files /not_exists @octane;
29+
}
30+
31+
location / {
32+
try_files $uri $uri/ @octane;
33+
34+
add_header X-Served-By kool.dev;
35+
}
36+
37+
location @octane {
38+
set $suffix "";
39+
40+
if ($uri = /index.php) {
41+
set $suffix ?$query_string;
42+
}
43+
44+
proxy_http_version 1.1;
45+
proxy_set_header Host $http_host;
46+
proxy_set_header Scheme $scheme;
47+
proxy_set_header SERVER_PORT $server_port;
48+
proxy_set_header REMOTE_ADDR $remote_addr;
49+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
50+
proxy_set_header Upgrade $http_upgrade;
51+
proxy_set_header Connection $connection_upgrade;
52+
53+
proxy_pass http://127.0.0.1:8000$suffix;
54+
}
55+
56+
location ~ /\.ht {
57+
deny all;
58+
}
59+
60+
# good practices
61+
add_header X-Frame-Options "SAMEORIGIN";
62+
63+
# basic H5BP suggestions
64+
include h5bp/internet_explorer/x-ua-compatible.conf;
65+
include h5bp/security/referrer-policy.conf;
66+
include h5bp/security/x-content-type-options.conf;
67+
include h5bp/security/x-xss-protection.conf;
68+
69+
# performance enhancements (mostly for caching static data)
70+
include h5bp/web_performance/cache-file-descriptors.conf;
71+
include h5bp/web_performance/pre-compressed_content_gzip.conf;
72+
}

8.0-swoole-nginx-prod/entrypoint

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
set -e
3+
4+
5+
# Run as current user
6+
CURRENT_USER=${ASUSER:-${UID:-0}}
7+
8+
if [ ! -z "$CURRENT_USER" ] && [ "$CURRENT_USER" != "0" ]; then
9+
usermod -u $CURRENT_USER kool
10+
fi
11+
12+
dockerize -template /kool/kool.tmpl:/usr/local/etc/php/conf.d/kool.ini -template /kool/zz-docker.tmpl:/usr/local/etc/php-fpm.d/zz-docker.conf -template /kool/default.tmpl:/etc/nginx/conf.d/default.conf
13+
14+
/kool/30-tune-worker-processes.sh
15+
16+
# Run entrypoint if provided
17+
if [ ! -z "$ENTRYPOINT" ] && [ -f "$ENTRYPOINT" ]; then
18+
bash $ENTRYPOINT
19+
fi
20+
21+
if [ "$1" = "sh" ] || [ "$1" = "bash" ] || [ "$1" = "php-fpm" ] || [ "$1" = "nginx" ] || [ "$1" = "supervisord" ]; then
22+
exec "$@"
23+
else
24+
exec su-exec kool "$@"
25+
fi

8.0-swoole-nginx-prod/supervisor.conf

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[program:nginx]
2+
depends_on = php-fpm
3+
command = nginx -g "daemon off;"
4+
stopasgroup = true
5+
stderr_logfile = /dev/stderr
6+
stdout_logfile = /dev/stdout
7+
8+
[program:octane]
9+
command = php artisan octane:start --server=swoole
10+
stopasgroup = true
11+
stderr_logfile = /dev/stderr
12+
stdout_logfile = /dev/stdout

8.0-swoole-nginx/Dockerfile

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
FROM debian AS cert
2+
3+
WORKDIR /kool/ssl
4+
5+
RUN apt-get update && \
6+
apt-get install -y openssl && \
7+
openssl genrsa -des3 -passout pass:x -out server.pass.key 2048 && \
8+
openssl rsa -passin pass:x -in server.pass.key -out _.localhost.key && \
9+
rm server.pass.key && \
10+
openssl req -new -key _.localhost.key -out server.csr \
11+
-subj "/C=XX/ST=XX/L=XX/O=Kool-Local/OU=Localhost/CN=*.localhost" && \
12+
openssl x509 -req -days 365 -in server.csr -signkey _.localhost.key -out _.localhost.crt && \
13+
openssl x509 -in _.localhost.crt -out _.localhost.pem
14+
15+
FROM kooldev/php:8.0-swoole
16+
17+
ENV PHP_FPM_LISTEN=/run/php-fpm.sock \
18+
NGINX_LISTEN=80 \
19+
NGINX_HTTPS=false \
20+
NGINX_LISTEN_HTTPS=443 \
21+
NGINX_HTTPS_CERT=/kool/ssl/_.localhost.pem \
22+
NGINX_HTTPS_CERT_KEY=/kool/ssl/_.localhost.key \
23+
NGINX_ROOT=/app/public \
24+
NGINX_INDEX=index.php \
25+
NGINX_CLIENT_MAX_BODY_SIZE=25M \
26+
NGINX_PHP_FPM=unix:/run/php-fpm.sock \
27+
NGINX_FASTCGI_READ_TIMEOUT=60s \
28+
NGINX_FASTCGI_BUFFERS='8 8k' \
29+
NGINX_FASTCGI_BUFFER_SIZE='16k' \
30+
NGINX_ENTRYPOINT_WORKER_PROCESSES_AUTOTUNE=true
31+
32+
RUN curl -L https://github.com/ochinchina/supervisord/releases/download/v0.6.3/supervisord_static_0.6.3_linux_amd64 -o /usr/local/bin/supervisord \
33+
&& chmod +x /usr/local/bin/supervisord \
34+
&& apk add --no-cache nginx \
35+
&& chown -R kool:kool /var/lib/nginx \
36+
&& chmod 770 /var/lib/nginx/tmp \
37+
&& ln -sf /dev/stdout /var/log/nginx/access.log \
38+
&& ln -sf /dev/stderr /var/log/nginx/error.log \
39+
# add h5bp/server-configs-nginx
40+
&& mkdir -p /etc/nginx/conf.d \
41+
&& mkdir /etc/nginx/h5bp \
42+
&& cd /etc/nginx/h5bp \
43+
&& wget https://github.com/h5bp/server-configs-nginx/archive/refs/tags/3.3.0.tar.gz -O h5bp.tgz \
44+
&& tar xzvf h5bp.tgz \
45+
&& rm -f h5bp.tgz \
46+
&& mv server-configs-nginx-*/h5bp/* . \
47+
&& mv server-configs-nginx-*/nginx.conf /etc/nginx/nginx.conf \
48+
&& sed -i "s|^user .*|user\ kool kool;|g" /etc/nginx/nginx.conf \
49+
&& mv server-configs-nginx-*/mime.types /etc/nginx/mime.types \
50+
&& rm -rf server-configs-nginx-* \
51+
&& curl -L https://raw.githubusercontent.com/nginxinc/docker-nginx/master/entrypoint/30-tune-worker-processes.sh -o /kool/30-tune-worker-processes.sh \
52+
&& chmod +x /kool/30-tune-worker-processes.sh
53+
54+
COPY supervisor.conf /kool/supervisor.conf
55+
COPY default.tmpl /kool/default.tmpl
56+
COPY entrypoint /kool/entrypoint
57+
COPY --from=cert /kool/ssl /kool/ssl
58+
RUN chmod +x /kool/entrypoint
59+
60+
EXPOSE 80
61+
62+
CMD [ "supervisord", "-c", "/kool/supervisor.conf" ]

0 commit comments

Comments
 (0)