Skip to content

Commit

Permalink
Merge #250 [backport25] Devcontainer on arm with php 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gsztupov committed Mar 11, 2024
2 parents 35e7357 + 907c8f2 commit ca52113
Show file tree
Hide file tree
Showing 14 changed files with 253 additions and 184 deletions.
98 changes: 69 additions & 29 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,47 +1,87 @@
FROM ubuntu:focal
FROM ubuntu:jammy

ARG DEBIAN_FRONTEND=noninteractive

# PHP
RUN apt-get update -y
RUN apt-get update -y && \
apt install -y apache2 vim software-properties-common sudo nano gnupg2

RUN apt-get install --no-install-recommends -y \
php7.4 \
php7.4-gd \
php7.4-zip \
php7.4-curl \
php7.4-xml \
php7.4-mbstring \
php7.4-sqlite \
php7.4-xdebug \
php7.4-pgsql \
php7.4-intl \
php7.4-imagick \
php7.4-gmp \
php7.4-apcu \
php7.4-bcmath \
php8.1 \
php8.1-common \
php8.1-gd \
php8.1-zip \
php8.1-curl \
php8.1-xml \
php8.1-xmlrpc \
php8.1-mbstring \
php8.1-sqlite \
php8.1-xdebug \
php8.1-pgsql \
php8.1-intl \
php8.1-imagick \
php8.1-gmp \
php8.1-apcu \
php8.1-bcmath \
php8.1-redis \
php8.1-soap \
php8.1-imap \
php8.1-opcache \
php8.1-cli \
php8.1-dev \
libmagickcore-6.q16-3-extra \
curl \
vim \
lsof \
make \
nodejs \
npm
unzip

# Composer
RUN curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php && \
curl -sS https://composer.github.io/installer.sig -o /tmp/composer-setup.sig && \
php -r "if (hash_file('sha384', '/tmp/composer-setup.php') !== trim(file_get_contents('/tmp/composer-setup.sig'))) { echo 'Composer installation failed, invalid hash'; exit(1); }" && \
php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer && \
rm /tmp/composer-setup.php /tmp/composer-setup.sig

RUN echo "xdebug.remote_enable = 1" >> /etc/php/7.4/cli/conf.d/20-xdebug.ini
RUN echo "xdebug.remote_autostart = 1" >> /etc/php/7.4/cli/conf.d/20-xdebug.ini
RUN echo "xdebug.remote_enable = 1" >> /etc/php/8.1/cli/conf.d/20-xdebug.ini && \
echo "xdebug.remote_autostart = 1" >> /etc/php/8.1/cli/conf.d/20-xdebug.ini && \
echo "apc.enable_cli=1" >> /etc/php/8.1/cli/conf.d/20-apcu.ini

# Autostart XDebug for apache
RUN { \
echo "xdebug.mode=debug"; \
echo "xdebug.start_with_request=yes"; \
} >> /etc/php/8.1/apache2/conf.d/20-xdebug.ini

# Docker
RUN apt-get -y install \
apt-transport-https \
ca-certificates \
curl \
jq \
gnupg-agent \
software-properties-common
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
RUN add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
software-properties-common && \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - && \
add-apt-repository \
"deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
RUN apt-get update -y
RUN apt-get install -y docker-ce docker-ce-cli containerd.io
RUN ln -s /var/run/docker-host.sock /var/run/docker.sock
stable" && \
apt-get update -y && \
apt-get install -y docker-ce docker-ce-cli containerd.io && \
ln -s /var/run/docker-host.sock /var/run/docker.sock

# Dedicated DevContainer user runs Apache
ENV APACHE_RUN_USER=devcontainer
ENV APACHE_RUN_GROUP=devcontainer
RUN useradd -ms /bin/bash ${APACHE_RUN_USER} && \
adduser ${APACHE_RUN_USER} sudo && \
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers && \
sed -ri "s/^export APACHE_RUN_USER=.*$/export APACHE_RUN_USER=${APACHE_RUN_USER}/" "/etc/apache2/envvars" && \
sed -ri "s/^export APACHE_RUN_GROUP=.*$/export APACHE_RUN_GROUP=${APACHE_RUN_GROUP}/" "/etc/apache2/envvars"

USER devcontainer

# NVM
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
RUN bash --login -i -c 'source /home/devcontainer/.bashrc && nvm install 16'

WORKDIR /var/www/html
15 changes: 15 additions & 0 deletions .devcontainer/apps.config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
$CONFIG = array (
'apps_paths' => array (
0 => array (
'path' => OC::$SERVERROOT.'/customapps',
'url' => '/customapps',
'writable' => true,
),
1 => array (
'path' => OC::$SERVERROOT.'/apps',
'url' => '/apps',
'writable' => true,
),
),
);
12 changes: 8 additions & 4 deletions .devcontainer/codespace.config.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
<?php

$cloudEnvironmentId = getenv('CLOUDENV_ENVIRONMENT_ID');
$codespaceName = getenv('CODESPACE_NAME');
$codespaceDomain = getenv('GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN');

$CONFIG = [
'mail_from_address' => 'no-reply',
'mail_smtpmode' => 'smtp',
'mail_sendmailmode' => 'smtp',
'mail_domain' => 'example.com',
'mail_smtphost' => 'localhost',
'mail_smtphost' => 'mailhog',
'mail_smtpport' => '1025',
'memcache.local' => '\OC\Memcache\APCu',
];

if($cloudEnvironmentId !== true) {
$CONFIG['overwritehost'] = $cloudEnvironmentId . '-80.apps.codespaces.githubusercontent.com';
if(is_string($codespaceName) && !empty($codespaceName) && is_string($codespaceDomain) && !empty($codespaceDomain)) {
$host = $codespaceName . '-80.' . $codespaceDomain;
$CONFIG['overwritehost'] = $host;
$CONFIG['overwrite.cli.url'] = 'https://' . $host;
$CONFIG['overwriteprotocol'] = 'https';
$CONFIG['trusted_domains'] = [ $host ];
}
27 changes: 16 additions & 11 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@
8080,
8025
],
"runArgs": [
"--privileged"
],
"extensions": [
"felixfbecker.php-debug",
"felixfbecker.php-intellisense",
"ms-azuretools.vscode-docker"
],
"settings": {
"php.suggest.basic": false,
}
"customizations": {
"vscode": {
"extensions": [
"felixfbecker.php-debug",
"felixfbecker.php-intellisense",
"ms-azuretools.vscode-docker",
"xdebug.php-debug",
"donjayamanne.githistory"
],
"settings": {
"php.suggest.basic": false
}
}
},
"workspaceFolder": "/var/www/html",
"remoteUser": "devcontainer"
}
40 changes: 32 additions & 8 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,49 @@ services:
volumes:
- .:/workspace:cached
- /var/run/docker.sock:/var/run/docker-host.sock
command: /bin/sh -c "while sleep 1000; do :; done"
- ..:/var/www/html
- ../../customapps:/var/www/html/customapps
- ../../data:/var/www/html/data
- ../../config:/var/www/html/config
command: /var/www/html/.devcontainer/entrypoint.sh
ports:
- 80:80
- 8080:8080
- 8025:8025

depends_on:
db:
condition: service_healthy
mailhog:
condition: service_started

db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: postgres
network_mode: service:nextclouddev

PGDATA: /data/postgres
volumes:
- ../../data/db:/data/postgres
expose:
- "5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 10s
timeout: 5s
retries: 10


adminer:
image: adminer
restart: always
network_mode: service:nextclouddev
ports:
- 8080:8080
depends_on:
db:
condition: service_healthy

mailhog:
image: mailhog/mailhog
restart: always
network_mode: service:nextclouddev
ports:
- 8025:8025


5 changes: 5 additions & 0 deletions .devcontainer/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

sudo service apache2 start

while sleep 1000; do :; done
14 changes: 14 additions & 0 deletions .devcontainer/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003
}
]
}
4 changes: 4 additions & 0 deletions .devcontainer/lock.config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
$CONFIG = array (
'config_is_read_only' => true,
);
11 changes: 11 additions & 0 deletions .devcontainer/nmc.config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
$CONFIG = array (
'htaccess.RewriteBase' => '/',
'default_language' => 'de_DE',
'integrity.check.disabled' => true, // not recommended for prod, but for customisation
'auth.authtoken.v1.disabled' => true,
'sharing.force_share_accept' => true,
'status-email-message-provider' => '\\OCA\\EmailTemplateExample\\MessageProvider',
'mail_template_class' => 'OCA\\EmailTemplateExample\\EMailTemplate',
// "logfile_office_report" => "/var/log/nextcloud/office.log",
);
43 changes: 43 additions & 0 deletions .devcontainer/nmcsetup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" >/dev/null 2>&1 && pwd )"

cd $DIR/

# after installation, do some MagentaCLOUD specific setups to start closer to production

# customapps directory split
cp .devcontainer/apps.config.php config/apps.config.php
cp .devcontainer/nmc.config.php config/nmc.config.php

# disable user themeing
sudo -u ${APACHE_RUN_USER} php occ theming:config disable-user-theming yes

# fixed themeing for MagentaCLOUD
cp .devcontainer/theme.config.php config/theme.config.php

# refresh .htaccess for short URL notation
sudo -u ${APACHE_RUN_USER} php occ maintenance:update:htaccess

# "Organisational" setting
sudo -u ${APACHE_RUN_USER} php occ theming:config color "#e20074" # don't use uppercase letters!
sudo -u ${APACHE_RUN_USER} php occ theming:config name MagentaCLOUD
sudo -u ${APACHE_RUN_USER} php occ theming:config slogan "Alle Dateien sicher an einem Ort"
sudo -u ${APACHE_RUN_USER} php occ theming:config imprintUrl "http://www.telekom.de/impressum"
sudo -u ${APACHE_RUN_USER} php occ theming:config privacyUrl "https://static.magentacloud.de/Datenschutz"

# app settings
sudo -u ${APACHE_RUN_USER} php occ config:app:set theming AndroidClientUrl --value \
"https://play.google.com/store/apps/details?=com.t_systems.android.webdav"
sudo -u ${APACHE_RUN_USER} php occ config:app:set theming iTunesAppId --value "312838242"
sudo -u ${APACHE_RUN_USER} php occ config:app:set theming iOSClientUrl --value \
"https://apps.apple.com/us/app/magentacloud-cloud-speicher/id312838242"

# enable/disable apps
sudo -u ${APACHE_RUN_USER} php occ app:enable nmctheme
sudo -u ${APACHE_RUN_USER} php occ app:disable dashboard # may remove as soon as dashboard CR is implemented

# there are side effects when using devcontainer and
# doing the main settings via webapp. For the moment, the best
# workaround is to lock config and avoid overwrite by nextcloud
# esp. on container rebuild
cp .devcontainer/lock.config.php config/lock.config.php
32 changes: 31 additions & 1 deletion .devcontainer/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,35 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" >/dev/null 2>&1 && pwd )"
cd $DIR/
git submodule update --init

# Codespace config
# VSCode debugger profile
mkdir -p .vscode && cp .devcontainer/launch.json .vscode/launch.json

# Onetime installation setup
if [[ ! $(sudo -u ${APACHE_RUN_USER} php occ status) =~ installed:[[:space:]]*true ]]; then
echo "Running NC installation"

# we could be faced with an externalized, empty config dir
touch config/CAN_INSTALL

# this produces the plain config file without any overwriting
sudo -u ${APACHE_RUN_USER} php occ maintenance:install \
--verbose \
--database=pgsql \
--database-name=postgres \
--database-host=db \
--database-port=5432 \
--database-user=postgres \
--database-pass=postgres \
--admin-user admin \
--admin-pass admin
fi

# Codespace config; do it late to avoid duplication into config.php
# (which removed the conditional code!)
# may consider setting 'config_is_read_only' => true,
cp .devcontainer/codespace.config.php config/codespace.config.php

# add MagentaCLOUD convenience setup
source .devcontainer/nmcsetup.sh

sudo service apache2 restart
5 changes: 5 additions & 0 deletions .devcontainer/theme.config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
$CONFIG = array (
'enforce_theme' => 'default', // or any other theme contained in the app
'theme' => '', // disable old themeing
);
Loading

0 comments on commit ca52113

Please sign in to comment.