Skip to content

Commit 43c8c5c

Browse files
committed
init
1 parent 628aed5 commit 43c8c5c

11 files changed

+841
-0
lines changed

green-metrics-tool/Dockerfile

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
FROM php:8.4-apache-trixie
2+
3+
ARG GIT_REF=master
4+
ARG NEXTCLOUD_REPO=https://github.com/nextcloud/server.git
5+
ARG NODE_VERSION=25.2.1
6+
7+
RUN apt-get update && apt-get install -y --no-install-recommends \
8+
git unzip rsync nano less \
9+
libpng-dev libjpeg62-turbo-dev libfreetype6-dev \
10+
libzip-dev libxml2-dev libicu-dev libgmp-dev \
11+
libbz2-dev libexif-dev libwebp-dev \
12+
libmagickwand-dev util-linux sudo \
13+
ca-certificates curl \
14+
&& rm -rf /var/lib/apt/lists/*
15+
16+
17+
RUN set -eux; \
18+
arch="$(dpkg --print-architecture)"; \
19+
case "$arch" in \
20+
amd64) node_arch='x64' ;; \
21+
arm64) node_arch='arm64' ;; \
22+
armhf) node_arch='armv7l' ;; \
23+
*) echo "Unsupported architecture: $arch"; exit 1 ;; \
24+
esac; \
25+
curl -fsSLO "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${node_arch}.tar.xz"; \
26+
tar -xJf "node-v${NODE_VERSION}-linux-${node_arch}.tar.xz" -C /usr/local --strip-components=1 --no-same-owner; \
27+
rm "node-v${NODE_VERSION}-linux-${node_arch}.tar.xz"; \
28+
ln -s /usr/local/bin/node /usr/local/bin/nodejs
29+
30+
RUN docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp \
31+
&& docker-php-ext-install -j"$(nproc)" \
32+
gd \
33+
bcmath \
34+
bz2 \
35+
exif \
36+
intl \
37+
gmp \
38+
opcache \
39+
pcntl \
40+
pdo_mysql \
41+
zip \
42+
xml \
43+
mysqli
44+
45+
46+
RUN pecl install redis apcu && docker-php-ext-enable redis apcu
47+
48+
RUN pecl install imagick && docker-php-ext-enable imagick || true
49+
50+
RUN a2enmod rewrite headers env dir mime setenvif
51+
52+
RUN mkdir /var/www/.npm && sudo chown -R www-data:www-data /var/www/.npm
53+
RUN mkdir mkdir /var/www/.cache && sudo chown -R www-data:www-data /var/www/.cache
54+
55+
RUN { \
56+
echo "memory_limit=512M"; \
57+
echo "upload_max_filesize=512M"; \
58+
echo "post_max_size=512M"; \
59+
echo "max_execution_time=360"; \
60+
echo "output_buffering=0"; \
61+
} > /usr/local/etc/php/conf.d/nextcloud.ini
62+
63+
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
64+
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer \
65+
&& rm composer-setup.php
66+
67+
#COPY nextcloud/ ./
68+
#RUN git clone --single-branch --depth=1 --branch "$GIT_REF" --recurse-submodules "$NEXTCLOUD_REPO" /usr/src/nextcloud
69+
RUN set -eux; \
70+
git init /usr/src/nextcloud; \
71+
cd /usr/src/nextcloud; \
72+
git remote add origin "$NEXTCLOUD_REPO"; \
73+
if echo "$GIT_REF" | grep -Eq '^[0-9a-f]{7,40}$'; then \
74+
# GIT_REF looks like a commit SHA
75+
git fetch --depth=1 origin "$GIT_REF"; \
76+
git checkout --detach FETCH_HEAD; \
77+
else \
78+
# GIT_REF is a branch or tag
79+
git fetch --depth=1 --tags origin "$GIT_REF"; \
80+
git checkout -q "$GIT_REF"; \
81+
fi; \
82+
# bring in submodules shallowly
83+
git submodule update --init --recursive --depth=1
84+
85+
WORKDIR /usr/src/nextcloud
86+
87+
88+
RUN if [ -d .git ]; then \
89+
git remote set-url origin "$NEXTCLOUD_REPO" || true; \
90+
fi
91+
92+
# RUN if [ -d .git ]; then \
93+
# git fetch --all --tags; \
94+
# git checkout "$GIT_REF"; \
95+
# git submodule update --init --recursive; \
96+
# else \
97+
# echo "WARNING: ./nextcloud has no .git; skipping fetch/checkout/submodules"; \
98+
# fi
99+
100+
ENV COMPOSER_ALLOW_SUPERUSER=1
101+
RUN if [ -f composer.json ]; then composer install --no-dev -o --no-interaction --no-ansi || true; fi
102+
103+
104+
WORKDIR /var/www/html
105+
RUN rm -rf /var/www/html/* \
106+
&& rsync -a /usr/src/nextcloud/ /var/www/html/ \
107+
&& chown -R www-data:www-data /var/www/html
108+
109+
RUN mkdir -p /var/www/html/config /var/www/html/data /var/www/html/custom_apps /var/www/html/themes \
110+
&& chown -R www-data:www-data /var/www/html
111+
112+
113+
HEALTHCHECK --interval=30s --timeout=10s --retries=10 \
114+
CMD php -r 'echo file_exists("/var/www/html/index.php") ? "OK" : "NO";' | grep -q OK || exit 1
115+
116+
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
117+
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
118+
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
119+
120+
EXPOSE 80
121+
CMD ["apache2-foreground"]

green-metrics-tool/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This measures the nextcloud text app with the Green Metrics Tool

green-metrics-tool/compose.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
services:
2+
app:
3+
build:
4+
context: .
5+
# args:
6+
# - GIT_REF: __GMT_VAR_NCHASH__
7+
image: my-nextcloud:master
8+
restart: unless-stopped
9+
shm_size: "256m"
10+
depends_on:
11+
- db
12+
# - redis
13+
environment:
14+
# REDIS_HOST: redis
15+
PHP_MEMORY_LIMIT: 512M
16+
HOST_URL: http://app
17+
18+
19+
#volumes:
20+
# Persist only what should be writable:
21+
# - nextcloud_data:/var/www/html/data
22+
# - nextcloud_config:/var/www/html/config
23+
# - nextcloud_apps:/var/www/html/custom_apps
24+
# - nextcloud_theme:/var/www/html/themes
25+
# ports:
26+
# - "8080:80" # access at http://localhost:8080
27+
#- "8443:443"
28+
29+
# cron:
30+
# image: my-nextcloud:master
31+
# container_name: nextcloud-cron
32+
# restart: unless-stopped
33+
# depends_on:
34+
# - app
35+
# volumes:
36+
# - nextcloud_data:/var/www/html/data
37+
# - nextcloud_config:/var/www/html/config
38+
# - nextcloud_apps:/var/www/html/custom_apps
39+
# - nextcloud_theme:/var/www/html/themes
40+
# entrypoint: ["/bin/sh","-c"]
41+
# command: >
42+
# 'until [ -f /var/www/html/config/config.php ]; do
43+
# echo "Waiting for Nextcloud installation...";
44+
# sleep 5;
45+
# done;
46+
# echo "Nextcloud installed, starting cron loop";
47+
# while true; do
48+
# su -s /bin/sh -c "php -f /var/www/html/cron.php" www-data;
49+
# sleep 300;
50+
# done'
51+
52+
gcb-playwright:
53+
image: greencoding/gcb_playwright:v21
54+
volumes:
55+
- /tmp/.X11-unix:/tmp/.X11-unix # for debugging in non-headless mode
56+
# - .:/tmp/repo
57+
environment:
58+
DISPLAY: ":0" # for debugging in non-headless mode
59+
#tty: true # nice to have for interactive shells
60+
#stdin_open: true # "
61+
command: [ "tail", "-f", "/dev/null" ] # keep container running
62+
db:
63+
image: mariadb:10.11
64+
restart: unless-stopped
65+
environment:
66+
MARIADB_AUTO_UPGRADE: "1"
67+
MYSQL_ROOT_PASSWORD: supersecretroot
68+
MYSQL_DATABASE: nextcloud
69+
MYSQL_USER: nextcloud
70+
MYSQL_PASSWORD: nextcloud
71+
command: ["--transaction-isolation=READ-COMMITTED", "--binlog-format=ROW", "--innodb-read-only-compressed=OFF"]
72+
# volumes:
73+
# - db_data:/var/lib/mysql
74+
75+
# redis:
76+
# image: redis:7-alpine
77+
# container_name: nextcloud-redis
78+
# restart: unless-stopped
79+
# command: ["redis-server", "--save", "", "--appendonly", "no"]
80+
# volumes:
81+
# - redis_data:/data
82+
83+
# volumes:
84+
# nextcloud_data:
85+
# nextcloud_config:
86+
# nextcloud_apps:
87+
# nextcloud_theme:
88+
# db_data:
89+
# redis_data:
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
set -e
3+
4+
DOCROOT=/var/www/html
5+
NC_USER=www-data
6+
CONFIG="$DOCROOT/config/config.php"
7+
8+
# Ensure writable paths exist and have correct perms
9+
mkdir -p "$DOCROOT/config" "$DOCROOT/data" "$DOCROOT/custom_apps" "$DOCROOT/themes"
10+
chown -R $NC_USER:$NC_USER "$DOCROOT/config" "$DOCROOT/data" "$DOCROOT/custom_apps" "$DOCROOT/themes"
11+
chmod 770 "$DOCROOT/config" "$DOCROOT/data"
12+
13+
exec "$@"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import contextlib
2+
import random
3+
import string
4+
from time import time_ns, sleep
5+
from playwright.sync_api import TimeoutError
6+
7+
8+
def login_nextcloud(page, username='nextcloud', password='nextcloud', domain='http://app'):
9+
page.goto(f"{domain}/login")
10+
page.locator('#user').fill(username)
11+
page.locator('#password').fill(password)
12+
page.locator('#password').press("Enter")
13+
14+
15+
def get_random_text(size_in_bytes) -> str:
16+
characters = string.ascii_letters + string.digits
17+
return ''.join(random.choice(characters) for _ in range(size_in_bytes))
18+
19+
def log_note(message: str) -> None:
20+
timestamp = str(time_ns())[:16]
21+
print(f"{timestamp} {message}")
22+
23+
24+
def close_modal(page) -> None:
25+
return
26+
with contextlib.suppress(TimeoutError):
27+
user_sleep() # Sleep to make sure the modal has time to appear before continuing navigation
28+
page.locator('#firstrunwizard .modal-container__content button[aria-label=Close]').click(timeout=15_000)
29+
30+
31+
def timeout_handler(signum, frame):
32+
raise TimeoutError("Page.content() timed out")
33+
34+
def user_sleep(delay=5):
35+
log_note(f"Sleeping for {delay}s")
36+
sleep(delay)

0 commit comments

Comments
 (0)