Deploy production #30
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy production | |
on: workflow_dispatch | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Deploy production from git | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.PRIVATE_KEY }} | |
script: | | |
root_directory="/home/bitnami/htdocs-prod" | |
repo_directory="$root_directory/repo" | |
release_directory="$root_directory/releases" | |
current_directory="$release_directory/$(date '+%Y%m%d%H%M%S')" | |
# Clone bare repository | |
[ -d $repo_directory ] || git clone --mirror --depth 1 https://github.com/pjshwa/apnee.git $repo_directory | |
# Make new release directory, and shared links | |
mkdir -p $current_directory | |
mkdir -p $root_directory/shared/static | |
# Clone materials into new release directory from git branch | |
cd $repo_directory | |
git fetch --depth 1 origin master | |
git archive master | /usr/bin/env tar -x -f - -C $current_directory | |
# Symlink shared materials | |
cd $current_directory | |
ln -sfn $root_directory/shared/static | |
# Fill credentials | |
echo "<?php \$credentials = array('host' => 'localhost', 'user' => '${{ secrets.DBUSER }}', 'pass' => '${{ secrets.DBPASS }}', 'database' => 'pjshwa'); ?>" | tee -a $current_directory/credentials.php | |
# Sync assets | |
AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }} /home/bitnami/.pyenv/shims/aws s3 sync s3://pjshwa-homepage-assets/static ./static --delete | |
# Symlink current directory | |
cd $root_directory | |
ln -sfn $current_directory current | |
- name: Flush the PHP opcache | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.PRIVATE_KEY }} | |
script: sudo /opt/bitnami/php/bin/cachetool opcache:reset --fcgi=/opt/bitnami/php/var/run/www.sock |