Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy to strato #1

Merged
merged 12 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .dockerignore

This file was deleted.

89 changes: 40 additions & 49 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,60 @@ on:
push:
branches:
- master
- deploy-strato

jobs:
build:
name: Build Docker images
name: Build website .tar.gz
runs-on: ubuntu-latest
steps:
- name: Checkout master
uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: daanvm
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push christelmusic.nl-nginx
id: docker_build_christelmusic_nl_nginx
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile-nginx
push: true
tags: daanvm/christelmusic.nl-nginx:latest
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build .tar.gz file
run: |
docker build --tag local-img/zipper --target zipper .
docker create --name zipper local-img/zipper
docker cp zipper:/build.tar.gz ./build.tar.gz
docker rm -f zipper
shell: bash

- name: Build and push christelmusic.nl-php
id: docker_build_christelmusic_nl_php
uses: docker/build-push-action@v3
- uses: actions/upload-artifact@v4
with:
context: .
file: ./Dockerfile-php
push: true
tags: daanvm/christelmusic.nl-php:latest
cache-from: type=gha
cache-to: type=gha,mode=max
name: build-tar-gz
path: ./build.tar.gz

deploy-kubernetes:
name: Create Kubernetes resources
deploy:
name: Deploy website to Strato
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout master
uses: actions/checkout@v3

- name: Install doctl
uses: digitalocean/action-doctl@v2
- uses: actions/download-artifact@v4
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}

- name: Save DigitalOcean kubeconfig with short-lived credentials
run: doctl kubernetes cluster kubeconfig save --expiry-seconds 600 k8s-daanvm
name: build-tar-gz

- name: Create kubernetes resources
- name: Apt install sshpass
run: |
kubectl apply -f ./christelmusic.nl.yaml
sudo apt-get update
sudo apt-get -y install sshpass

- name: Deploy new latest version of docker image
- name: Upload to Strato
env:
SSHPASS: ${{ secrets.STRATO_SSH_PASSWORD }}
run: |
kubectl create secret generic ifttt --save-config --dry-run=client --from-literal='key=${{ secrets.IFTTT_KEY }}' -o yaml | kubectl apply -f -
kubectl create secret generic mail-orders-to --save-config --dry-run=client --from-literal='key=${{ secrets.MAIL_ORDERS_TO }}' -o yaml | kubectl apply -f -
kubectl rollout restart deployment christelmusic-nl
kubectl rollout restart deployment christelmusic-nl-php
sshpass -e scp -oStrictHostKeyChecking=no ./build.tar.gz ${{ secrets.STRATO_SSH_USERNAME }}@ssh.strato.com:build.tar.gz
sshpass -e ssh -oStrictHostKeyChecking=no ${{ secrets.STRATO_SSH_USERNAME }}@ssh.strato.com << EOF
rm -rf ./new-release
mkdir new-release
cd new-release
tar -xzvf ../build.tar.gz
cd ..
rm -f ./build.tar.gz

echo "IFTTT_KEY=${{ secrets.IFTTT_KEY }}" > ./new-release/.env
echo "MAIL_ORDERS_TO=${{ secrets.MAIL_ORDERS_TO }}" >> ./new-release/.env

rm -rf ./prev-release
mv ./app ./prev-release
mv ./new-release ./app
rm -rf ./new-release
EOF
37 changes: 37 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM php:8.1-apache as base

# Use the default production configuration
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

COPY app /var/www/html

FROM base as builder

# Install php dependencies
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && \
install-php-extensions imagick pcntl zip

# Install composer dependencies
COPY --from=composer /usr/bin/composer /usr/bin/composer
WORKDIR /var/www/html
RUN composer install

# Allow the creation of pdf files
RUN sed -i '/disable ghostscript format types/,+6d' /etc/ImageMagick-6/policy.xml

COPY .env.example .env

# Create cache
RUN /var/www/html/scripts/christelmusic warmup

FROM builder as zipper

RUN cd /var/www/html && tar -czvf /build.tar.gz .

FROM base

RUN a2enmod rewrite

COPY --from=builder /var/www/html/vendor /var/www/html/vendor
COPY --from=builder /var/www/html/cache /var/www/html/cache
9 changes: 0 additions & 9 deletions Dockerfile-nginx

This file was deleted.

23 changes: 0 additions & 23 deletions Dockerfile-php

This file was deleted.

2 changes: 2 additions & 0 deletions app/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
RewriteEngine on
RewriteRule ^(.*)$ public/$1 [QSA,L]
6 changes: 4 additions & 2 deletions app/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"ChristelMusic\\": "src"
},
"files": [
"parable_init.php"
"parable_init.php",
"dotenv_init.php"
]
},
"require": {
Expand All @@ -22,6 +23,7 @@
"moneyphp/money": "^3.3",
"parable-php/framework": "^2.0",
"parable-php/routing": "^1.0",
"parable-php/console": "^1.0"
"parable-php/console": "^1.0",
"vlucas/phpdotenv": "^5.6"
}
}
Loading
Loading