From b4bc4dba1b64717094c13f4a56a0abba2cdced3b Mon Sep 17 00:00:00 2001 From: lubiana Date: Sat, 15 Jun 2024 22:36:31 +0200 Subject: [PATCH 1/4] add dockerfile --- Dockerfile | 15 +++++++++++++++ composer.json | 6 +++--- 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..dfea58c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM git.php.fail/lubiana/container/php:8.3 +RUN mkdir /app +WORKDIR /app +COPY bin/console /app/bin/console +COPY config /app/config +COPY migrations /app/migrations +COPY public /app/public +COPY src /app/src +COPY templates /app/templates +COPY composer.json /app/composer.json +COPY composer.lock /app/composer.lock +COPY .env /app/.env +RUN mkdir /app/var +ENV APP_ENV=prod +RUN composer install --no-dev --optimize-autoloader \ No newline at end of file diff --git a/composer.json b/composer.json index 273625d..9a7f726 100644 --- a/composer.json +++ b/composer.json @@ -70,11 +70,11 @@ "assets:install %PUBLIC_DIR%": "symfony-cmd" }, "post-install-cmd": [ - "@auto-scripts", - "config-transformer switch-format config" + "@auto-scripts" ], "post-update-cmd": [ - "@auto-scripts" + "@auto-scripts", + "config-transformer switch-format config" ], "lint": [ "rector", -- 2.39.5 From 9f5bb8ce9fbca9fdccd385ba01dc57ba793dc7fd Mon Sep 17 00:00:00 2001 From: lubiana Date: Mon, 17 Jun 2024 22:41:47 +0200 Subject: [PATCH 2/4] add more deployment files --- .gitignore | 3 ++- Dockerfile | 15 --------------- deploy/Dockerfile | 2 ++ deploy/install.sh | 2 ++ deploy/prepare-deploy.sh | 26 ++++++++++++++++++++++++++ etc/caddy/Caddyfile | 6 ++++++ etc/php83/php-fpm.d/www.conf | 10 ++++++++++ var/.gitkeep | 0 8 files changed, 48 insertions(+), 16 deletions(-) delete mode 100644 Dockerfile create mode 100644 deploy/Dockerfile create mode 100644 deploy/install.sh create mode 100644 deploy/prepare-deploy.sh create mode 100644 etc/caddy/Caddyfile create mode 100644 etc/php83/php-fpm.d/www.conf create mode 100644 var/.gitkeep diff --git a/.gitignore b/.gitignore index 9a35500..67d0ef4 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,5 @@ .phpunit.result.cache ###< phpunit/phpunit ### -.idea/ \ No newline at end of file +.idea/ +/deploy/temp-deploy/ diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index dfea58c..0000000 --- a/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM git.php.fail/lubiana/container/php:8.3 -RUN mkdir /app -WORKDIR /app -COPY bin/console /app/bin/console -COPY config /app/config -COPY migrations /app/migrations -COPY public /app/public -COPY src /app/src -COPY templates /app/templates -COPY composer.json /app/composer.json -COPY composer.lock /app/composer.lock -COPY .env /app/.env -RUN mkdir /app/var -ENV APP_ENV=prod -RUN composer install --no-dev --optimize-autoloader \ No newline at end of file diff --git a/deploy/Dockerfile b/deploy/Dockerfile new file mode 100644 index 0000000..47bc55b --- /dev/null +++ b/deploy/Dockerfile @@ -0,0 +1,2 @@ +FROM git.php.fail/lubiana/container/php:8.3 as phpbuild + diff --git a/deploy/install.sh b/deploy/install.sh new file mode 100644 index 0000000..10ee492 --- /dev/null +++ b/deploy/install.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env sh + diff --git a/deploy/prepare-deploy.sh b/deploy/prepare-deploy.sh new file mode 100644 index 0000000..d612203 --- /dev/null +++ b/deploy/prepare-deploy.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env sh + +if [ -d "temp-deploy" ]; then + rm -rf temp-deploy +fi +mkdir temp-deploy +cd temp-deploy || return + +pathsToCopy="public bin config migrations src templates composer.json composer.lock symfony.lock .env etc" + +for path in $pathsToCopy +do + cp -r ../../"$path" ./ +done + +rm ./bin/phpunit +APP_ENV=prod composer install --no-dev -a +mkdir -p ~/.ssh/ +# Print the SSH key, replacing newline characters with actual new lines +echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa +# Set appropriate permissions for the SSH key +chmod 600 ~/.ssh/id_rsa +# Add the remote host's key to the known_hosts file to avoid authenticity confirmation +ssh-keyscan -H $HOST >> ~/.ssh/known_hosts +# SCP files to the remote host +rsync -avz --delete public/ ${USERNAME}@${HOST}:${TARGETDIR} diff --git a/etc/caddy/Caddyfile b/etc/caddy/Caddyfile new file mode 100644 index 0000000..0447d1d --- /dev/null +++ b/etc/caddy/Caddyfile @@ -0,0 +1,6 @@ +:8087 { + root * /var/www/html/public + php_fastcgi unix//var/run/php-fpm.sock + file_server + encode zstd gzip +} \ No newline at end of file diff --git a/etc/php83/php-fpm.d/www.conf b/etc/php83/php-fpm.d/www.conf new file mode 100644 index 0000000..72bd8fb --- /dev/null +++ b/etc/php83/php-fpm.d/www.conf @@ -0,0 +1,10 @@ +[www] + +user = nobody +group = nobody +listen = /var/run/php-fpm.sock +pm = dynamic +pm.max_children = 5 +pm.start_servers = 2 +pm.min_spare_servers = 1 +pm.max_spare_servers = 3 \ No newline at end of file diff --git a/var/.gitkeep b/var/.gitkeep new file mode 100644 index 0000000..e69de29 -- 2.39.5 From ec46bf2884cc422d08eba73b96f7e23a235f9d0b Mon Sep 17 00:00:00 2001 From: lubiana Date: Tue, 18 Jun 2024 22:12:36 +0200 Subject: [PATCH 3/4] poddypodman --- {etc => deploy/etc}/caddy/Caddyfile | 0 {etc => deploy/etc}/php83/php-fpm.d/www.conf | 2 +- deploy/install.sh | 24 ++++++++++++++++++++ deploy/prepare-deploy.sh | 8 +++---- 4 files changed, 29 insertions(+), 5 deletions(-) rename {etc => deploy/etc}/caddy/Caddyfile (100%) rename {etc => deploy/etc}/php83/php-fpm.d/www.conf (67%) diff --git a/etc/caddy/Caddyfile b/deploy/etc/caddy/Caddyfile similarity index 100% rename from etc/caddy/Caddyfile rename to deploy/etc/caddy/Caddyfile diff --git a/etc/php83/php-fpm.d/www.conf b/deploy/etc/php83/php-fpm.d/www.conf similarity index 67% rename from etc/php83/php-fpm.d/www.conf rename to deploy/etc/php83/php-fpm.d/www.conf index 72bd8fb..113b8c2 100644 --- a/etc/php83/php-fpm.d/www.conf +++ b/deploy/etc/php83/php-fpm.d/www.conf @@ -2,7 +2,7 @@ user = nobody group = nobody -listen = /var/run/php-fpm.sock +listen = 9001 pm = dynamic pm.max_children = 5 pm.start_servers = 2 diff --git a/deploy/install.sh b/deploy/install.sh index 10ee492..6f09d2a 100644 --- a/deploy/install.sh +++ b/deploy/install.sh @@ -1,2 +1,26 @@ #!/usr/bin/env sh +podman pod create \ + --label "io.containers.autoupdate=registry" \ + --name futtern \ + -p 8087:8087 + +podman run -d \ + --pod futtern \ + --name php \ + git.php.fail/lubiana/container/php:8.3-fpm + +podman run -d \ + --pod futtern \ + --name caddy \ + --volume + docker.io/caddy/caddy:alpine + +podman genereate systemd \ + --files \ + --name futtern \ + --restart-policy=always \ + -t 10 + +mkdir -p ${HOME}/.config/systemd/user + diff --git a/deploy/prepare-deploy.sh b/deploy/prepare-deploy.sh index d612203..558f081 100644 --- a/deploy/prepare-deploy.sh +++ b/deploy/prepare-deploy.sh @@ -1,10 +1,10 @@ #!/usr/bin/env sh -if [ -d "temp-deploy" ]; then - rm -rf temp-deploy +if [ -d "futter-app" ]; then + rm -rf futtern-app fi -mkdir temp-deploy -cd temp-deploy || return +mkdir futtern-app +cd futtern-app || return pathsToCopy="public bin config migrations src templates composer.json composer.lock symfony.lock .env etc" -- 2.39.5 From c252b8420bdb0571d20223a4b1e13bee5e3e9b15 Mon Sep 17 00:00:00 2001 From: lubiana Date: Sat, 22 Jun 2024 21:47:23 +0200 Subject: [PATCH 4/4] prepare deploy --- .forgejo/workflows/release.yml | 20 ++++++++++++++++++++ .gitignore | 3 ++- deploy/etc/caddy/Caddyfile | 3 ++- deploy/install.sh | 27 ++++++++++++++++----------- deploy/prepare-deploy.sh | 12 ++++++++---- 5 files changed, 48 insertions(+), 17 deletions(-) create mode 100644 .forgejo/workflows/release.yml mode change 100644 => 100755 deploy/install.sh diff --git a/.forgejo/workflows/release.yml b/.forgejo/workflows/release.yml new file mode 100644 index 0000000..9602add --- /dev/null +++ b/.forgejo/workflows/release.yml @@ -0,0 +1,20 @@ +on: + release +jobs: + ls: + runs-on: docker + container: + image: git.php.fail/lubiana/container/php:ci + steps: + - name: Manually checkout + env: + REPO: '${{ github.repository }}' + TOKEN: '${{ secrets.GITHUB_TOKEN }}' + BRANCH: '${{ env.GITHUB_REF_NAME }}' + GIT_SERVER: 'hannover.ccc.de/gitlab' + run: | + git clone --branch $GITHUB_REF_NAME https://${TOKEN}@${GIT_SERVER}/${REPO}.git . + git fetch + git checkout ${{ github.head_ref }} + - name: list + run: ls diff --git a/.gitignore b/.gitignore index 67d0ef4..62752be 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,5 @@ ###< phpunit/phpunit ### .idea/ -/deploy/temp-deploy/ +/deploy/futtern-app/ +/deploy/var/ diff --git a/deploy/etc/caddy/Caddyfile b/deploy/etc/caddy/Caddyfile index 0447d1d..a36f02d 100644 --- a/deploy/etc/caddy/Caddyfile +++ b/deploy/etc/caddy/Caddyfile @@ -1,6 +1,7 @@ :8087 { + log root * /var/www/html/public - php_fastcgi unix//var/run/php-fpm.sock + php_fastcgi localhost:9001 file_server encode zstd gzip } \ No newline at end of file diff --git a/deploy/install.sh b/deploy/install.sh old mode 100644 new mode 100755 index 6f09d2a..d4b64b7 --- a/deploy/install.sh +++ b/deploy/install.sh @@ -1,5 +1,11 @@ #!/usr/bin/env sh +if [ ! -d "var" ]; then + mkdir var +fi +podman pod stop futtern +podman pod rm futtern + podman pod create \ --label "io.containers.autoupdate=registry" \ --name futtern \ @@ -7,20 +13,19 @@ podman pod create \ podman run -d \ --pod futtern \ - --name php \ + --name futtern-php \ + --volume $(pwd)/etc/php83/php-fpm.d/www.conf:/etc/php83/php-fpm.d/www.conf \ + --volume $(pwd)/futtern-app:/var/www/html \ + --volume $(pwd)/var:/var/www/html/var \ + --env 'APP_ENV=prod' \ git.php.fail/lubiana/container/php:8.3-fpm podman run -d \ --pod futtern \ - --name caddy \ - --volume + --name futtern-caddy \ + --volume $(pwd)/etc/caddy/Caddyfile:/etc/caddy/Caddyfile \ + --volume $(pwd)/futtern-app:/var/www/html \ + --volume caddy_data:/data \ docker.io/caddy/caddy:alpine -podman genereate systemd \ - --files \ - --name futtern \ - --restart-policy=always \ - -t 10 - -mkdir -p ${HOME}/.config/systemd/user - +echo 'yes' | podman exec -it futtern-php /var/www/html/bin/console doctrine:migrations:migrate diff --git a/deploy/prepare-deploy.sh b/deploy/prepare-deploy.sh index 558f081..c0ad1ed 100644 --- a/deploy/prepare-deploy.sh +++ b/deploy/prepare-deploy.sh @@ -1,10 +1,12 @@ #!/usr/bin/env sh -if [ -d "futter-app" ]; then - rm -rf futtern-app +TARGETDIR='futtern-app' + +if [ -d $TARGETDIR ]; then + rm -rf $TARGETDIR fi -mkdir futtern-app -cd futtern-app || return +mkdir $TARGETDIR +cd $TARGETDIR || return pathsToCopy="public bin config migrations src templates composer.json composer.lock symfony.lock .env etc" @@ -24,3 +26,5 @@ chmod 600 ~/.ssh/id_rsa ssh-keyscan -H $HOST >> ~/.ssh/known_hosts # SCP files to the remote host rsync -avz --delete public/ ${USERNAME}@${HOST}:${TARGETDIR} + + -- 2.39.5