Skip to content

Commit

Permalink
Merge branch 'feature/staging' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
mahiarirani committed Oct 14, 2024
2 parents cde9bdb + 29c859f commit 25c18af
Show file tree
Hide file tree
Showing 24 changed files with 622 additions and 107 deletions.
21 changes: 10 additions & 11 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
WWWUSER=1000
WWWGROUP=1000
APACHE_RUN_USER=www-user
APACHE_RUN_GROUP=www-group
ENV=development
NC_VERSION=28
APP_URL=localhost

DB_NAME=nextcloud
DB_USER=nextcloud
DB_PASSWORD=nextcloud
DB_ROOT_PASSWORD=rootpassword
MYSQL_DATABASE=nextcloud
MYSQL_USER=nextcloud
MYSQL_PASSWORD=
MYSQL_ROOT_PASSWORD=

NC_ADMIN_USER=swarmbox
NC_ADMIN_PASSWORD=swarmbox
REDIS_HOST_PASSWORD=

SWARM_ACCESS_API_TOKEN=Nz5lDX7PpPGrcdAI5SjPZHVdZJe12AuMOrKfZXaL
NEXTCLOUD_ADMIN_USER=swarmbox
NEXTCLOUD_ADMIN_PASSWORD=
22 changes: 22 additions & 0 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Staging

on:
push:
branches:
- staging

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ vars.STAGING_SERVER_HOST }}
username: deploy
key: ${{ secrets.STAGING_SSH_PRIVATE_KEY }}
script: bash deploy
14 changes: 14 additions & 0 deletions cli/dev/linux/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -euo pipefail

# stop and remove the containers and volumes
echo "stopping and removing the containers and volumes";
docker compose down --volumes --remove-orphans

# remove nextcloud source code
echo "removing nextcloud source code";
echo "need sudo password to remove dev-environment directory"
sudo rm -rf dev-environment

# done
echo "cleaned up the dev environment"
34 changes: 34 additions & 0 deletions cli/dev/linux/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash
set -euo pipefail

# add nextcloud.local to /etc/hosts
echo "checking if nextcloud.local is in /etc/hosts"
if ! grep -q "nextcloud.local" /etc/hosts; then
echo "adding nextcloud.local to /etc/hosts"
echo "need sudo password to add nextcloud.local to /etc/hosts"
echo "127.0.0.1 nextcloud.local" | sudo tee -a /etc/hosts
fi

# set up environment variables
echo "setting up environment variables"
if [ ! -f .env ]; then
echo "creating .env file"
cp .env.example .env
echo "setting up .env file"
perl -pi -e 's/REDIS_HOST_PASSWORD=/REDIS_HOST_PASSWORD=secret/g' .env
perl -pi -e 's/MYSQL_PASSWORD=/MYSQL_PASSWORD=secret/g' .env
perl -pi -e 's/MYSQL_ROOT_PASSWORD=/MYSQL_ROOT_PASSWORD=rootpassword/g' .env
perl -pi -e 's/NEXTCLOUD_ADMIN_PASSWORD=/NEXTCLOUD_ADMIN_PASSWORD=swarmbox/g' .env
perl -pi -e "s/APP_URL=localhost/APP_URL=nextcloud.local/g" .env
echo ".env file created"
else
echo ".env file already exists"
fi

# start the containers
echo "starting the containers"
docker compose up -d --force-recreate --remove-orphans --build

# done
echo "started the dev environment"
echo "visit https://nextcloud.local"
20 changes: 20 additions & 0 deletions cli/dev/windows/clean.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@echo off
REM Clean Script for Windows

REM Stop and remove Docker containers and volumes
echo Stopping and removing the containers and volumes
docker-compose down --volumes --remove-orphans

REM Remove Nextcloud source code
set devEnvironmentDir=dev-environment
if exist %devEnvironmentDir% (
echo Removing nextcloud source code
rmdir /S /Q %devEnvironmentDir%
echo Removed %devEnvironmentDir% directory
) else (
echo %devEnvironmentDir% does not exist
)

REM Done
echo Cleaned up the dev environment
pause
38 changes: 38 additions & 0 deletions cli/dev/windows/install.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
@echo off
REM Install Script for Windows

REM Check if nextcloud.local is in the hosts file
echo Checking if nextcloud.local is in C:\Windows\System32\drivers\etc\hosts
findstr /C:"nextcloud.local" C:\Windows\System32\drivers\etc\hosts >nul
if %errorlevel% neq 0 (
echo Adding nextcloud.local to hosts file
echo 127.0.0.1 nextcloud.local >> C:\Windows\System32\drivers\etc\hosts
) else (
echo nextcloud.local is already in the hosts file
)

REM Set up environment variables
if not exist ".env" (
echo Creating .env file
copy .env.example .env

echo Updating environment variables in .env file
powershell -Command "(Get-Content .env) -replace 'REDIS_HOST_PASSWORD=', 'REDIS_HOST_PASSWORD=secret' | Set-Content .env"
powershell -Command "(Get-Content .env) -replace 'MYSQL_PASSWORD=', 'MYSQL_PASSWORD=secret' | Set-Content .env"
powershell -Command "(Get-Content .env) -replace 'MYSQL_ROOT_PASSWORD=', 'MYSQL_ROOT_PASSWORD=rootpassword' | Set-Content .env"
powershell -Command "(Get-Content .env) -replace 'NEXTCLOUD_ADMIN_PASSWORD=', 'NEXTCLOUD_ADMIN_PASSWORD=swarmbox' | Set-Content .env"
powershell -Command "(Get-Content .env) -replace 'APP_URL=localhost', 'APP_URL=nextcloud.local' | Set-Content .env"

echo .env file created
) else (
echo .env file already exists
)

REM Start the Docker containers
echo Starting the containers
docker-compose up -d --force-recreate --remove-orphans --build

REM Done
echo Started the dev environment
echo Visit https://nextcloud.local
pause
19 changes: 19 additions & 0 deletions cli/staging/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
cd /opt/hejbit

deploy() {
local version=$1
cd hejbit-$version
git pull
npm install
npm run build
docker exec -u www-data hejbit-$version-nextcloud-1 php occ upgrade
}

for version in {28..30}
do
deploy $version &
done

wait

70 changes: 0 additions & 70 deletions docker-compose.yaml

This file was deleted.

118 changes: 118 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
services:

web:
build: ./docker/web
restart: unless-stopped
volumes_from:
- nextcloud
depends_on:
- nextcloud
labels:
caddy: ${APP_URL:-localhost}
caddy.reverse_proxy: '{{upstreams 80}}'
networks:
- frontend
- proxy

nextcloud:
build:
context: ./docker/nextcloud
dockerfile: ${NC_VERSION:-28}.Dockerfile
target: ${ENV:-production}
restart: unless-stopped
depends_on:
mariadb:
condition: service_healthy
redis:
condition: service_healthy
env_file:
- .env
environment:
MYSQL_HOST: mariadb:3306
REDIS_HOST: redis
networks:
- frontend
- backend
extra_hosts:
- host.docker.internal:host-gateway
volumes:
- nc-app:/var/www/html
- ./:/var/www/html/custom_apps/files_external_ethswarm

redis:
image: redis:alpine
restart: unless-stopped
environment:
REDIS_HOST_PASSWORD: ${REDIS_HOST_PASSWORD:-secret}
command: redis-server --requirepass ${REDIS_HOST_PASSWORD}
healthcheck:
test: ["CMD", "redis-cli", "ping"]
start_period: 3s
timeout: 5s
interval: 30s
networks:
- backend

mariadb:
image: mariadb:latest
# set transaction isolation: https://docs.nextcloud.com/server/stable/admin_manual/configuration_database/linux_database_configuration.html
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW --innodb-file-per-table=1 --skip-innodb-read-only-compressed
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-rootpassword}
MYSQL_DATABASE: ${MYSQL_DATABASE:-nextcloud}
MYSQL_USER: ${MYSQL_USER:-nextcloud}
MYSQL_PASSWORD: ${MYSQL_PASSWORD:-secret}
volumes:
- nc-db:/var/lib/mysql
healthcheck:
test: ["CMD", "healthcheck.sh", "--su-mysql", "--connect", "--innodb_initialized"]
start_period: 3s
timeout: 5s
interval: 30s
networks:
- backend

adminer:
image: adminer:latest
restart: unless-stopped
networks:
- backend
ports:
- '8080:8080'
depends_on:
- mariadb
environment:
ADMINER_DEFAULT_SERVER: mariadb
profiles:
- dev

rsync:
image: ogivuk/rsync
restart: unless-stopped
cpu_shares: 512
mem_limit: 256m
volumes:
- rsync:/rsync
- nc-app:/app:ro
- ./dev-environment/nextcloud_source:/source
command: rsync -avP -e /app/data/ /app/ /source/
depends_on:
- nextcloud
networks:
- backend
profiles:
- dev

volumes:
nc-app:
nc-db:
certs:
rsync:

networks:
frontend:
backend:
proxy:
external: true
name: hejbit-network
31 changes: 31 additions & 0 deletions docker/nextcloud/27.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM nextcloud:27-fpm-alpine AS base

FROM base AS production

ENV NEXTCLOUD_UPDATE=1

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"; \
{ \
echo "memory_limit=1024M"; \
echo "upload_max_filesize=16G"; \
echo "post_max_size=16G"; \
echo "max_execution_time=3600"; \
echo "max_input_time=3600"; \
} > /usr/local/etc/php/conf.d/nextcloud.ini;

COPY --chown=www-data ./hooks /docker-entrypoint-hooks.d

RUN mkdir -p /var/www/html/custom_apps && \
chown -R www-data:www-data /var/www/html/custom_apps


FROM production AS development

RUN apk add --update --no-cache linux-headers $PHPIZE_DEPS;
RUN pecl install xdebug && docker-php-ext-enable xdebug;
RUN { \
echo "xdebug.mode=develop,debug"; \
echo "xdebug.start_with_request=trigger"; \
echo "xdebug.discover_client_host=true"; \
echo "xdebug.client_host=host.docker.internal"; \
} >> /usr/local/etc/php/conf.d/nextcloud.ini;
Loading

0 comments on commit 25c18af

Please sign in to comment.