├── Dockerfile ├── LICENSE ├── action.yml ├── entrypoint.sh └── readme.md /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.11.3 2 | 3 | MAINTAINER Hoang Ngoc Quy 4 | 5 | RUN apk update \ 6 | && apk upgrade \ 7 | && apk add --no-cache rsync openssh-client \ 8 | && rm -rf /var/cache/apk/* 9 | 10 | COPY entrypoint.sh /script/entrypoint.sh 11 | 12 | WORKDIR /workspace 13 | 14 | ENTRYPOINT ["/bin/sh", "/script/entrypoint.sh"] 15 | 16 | CMD ["deploy"] 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Hoang Ngoc Quy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'Laravel Deploy' 2 | 3 | description: 'Deploy Laravel Application to Server via SSH by RSync' 4 | author: 'Hoang Ngoc Quy' 5 | branding: 6 | icon: 'send' 7 | color: 'green' 8 | 9 | inputs: 10 | user: 11 | description: 'Deploy user' 12 | required: true 13 | host: 14 | description: 'Deploy host' 15 | required: true 16 | port: 17 | description: 'Deploy port' 18 | required: false 19 | path: 20 | description: 'Path source on server' 21 | required: true 22 | owner: 23 | description: 'Deploy owner' 24 | required: true 25 | 26 | runs: 27 | using: 'docker' 28 | image: 'Dockerfile' 29 | args: 30 | - ${{ inputs.user }} 31 | - ${{ inputs.host }} 32 | - ${{ inputs.port }} 33 | - ${{ inputs.path }} 34 | - ${{ inputs.owner }} 35 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SSH_USER=$1 4 | SSH_HOST=$2 5 | SSH_PORT=$3 6 | PATH_SOURCE=$4 7 | OWNER=$5 8 | 9 | mkdir -p /root/.ssh 10 | ssh-keyscan -H "$SSH_HOST" >> /root/.ssh/known_hosts 11 | 12 | if [ -z "$DEPLOY_KEY" ]; 13 | then 14 | echo $'\n' "------ DEPLOY KEY NOT SET YET! ----------------" $'\n' 15 | exit 1 16 | else 17 | printf '%b\n' "$DEPLOY_KEY" > /root/.ssh/id_rsa 18 | chmod 400 /root/.ssh/id_rsa 19 | 20 | echo $'\n' "------ CONFIG SUCCESSFUL! ---------------------" $'\n' 21 | fi 22 | 23 | if [ ! -z "$SSH_PORT" ]; 24 | then 25 | printf "Host %b\n\tPort %b\n" "$SSH_HOST" "$SSH_PORT" > /root/.ssh/config 26 | ssh-keyscan -p $SSH_PORT -H "$SSH_HOST" >> /root/.ssh/known_hosts 27 | fi 28 | 29 | rsync --progress -avzh \ 30 | --exclude='.git/' \ 31 | --exclude='.git*' \ 32 | --exclude='.editorconfig' \ 33 | --exclude='.styleci.yml' \ 34 | --exclude='.idea/' \ 35 | --exclude='Dockerfile' \ 36 | --exclude='readme.md' \ 37 | --exclude='README.md' \ 38 | -e "ssh -i /root/.ssh/id_rsa" \ 39 | --rsync-path="sudo rsync" . $SSH_USER@$SSH_HOST:$PATH_SOURCE 40 | 41 | if [ $? -eq 0 ] 42 | then 43 | echo $'\n' "------ SYNC SUCCESSFUL! -----------------------" $'\n' 44 | echo $'\n' "------ RELOADING PERMISSION -------------------" $'\n' 45 | 46 | ssh -i /root/.ssh/id_rsa -t $SSH_USER@$SSH_HOST "sudo chown -R $OWNER:$OWNER $PATH_SOURCE" 47 | ssh -i /root/.ssh/id_rsa -t $SSH_USER@$SSH_HOST "sudo chmod 775 -R $PATH_SOURCE" 48 | ssh -i /root/.ssh/id_rsa -t $SSH_USER@$SSH_HOST "sudo chmod 777 -R $PATH_SOURCE/storage" 49 | ssh -i /root/.ssh/id_rsa -t $SSH_USER@$SSH_HOST "sudo chmod 777 -R $PATH_SOURCE/public" 50 | 51 | echo $'\n' "------ CONGRATS! DEPLOY SUCCESSFUL!!! ---------" $'\n' 52 | exit 0 53 | else 54 | echo $'\n' "------ DEPLOY FAILED! -------------------------" $'\n' 55 | exit 1 56 | fi 57 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | # Laravel Deploy 4 | 5 | [![ForTheBadge built-with-love](http://ForTheBadge.com/images/badges/built-with-love.svg)](https://ngocquyhoang.com) 6 | [![forthebadge](https://forthebadge.com/images/badges/contains-cat-gifs.svg)](https://ngocquyhoang.com) 7 | [![forthebadge](https://forthebadge.com/images/badges/powered-by-water.svg)](https://ngocquyhoang.com) 8 | 9 |
10 | 11 | 12 | ## Config example: 13 | 14 | ``` 15 | name: Build and Deploy 16 | on: 17 | push: 18 | branches: 19 | - master 20 | 21 | jobs: 22 | build: 23 | name: Build and Deploy 24 | runs-on: ubuntu-latest 25 | steps: 26 | - name: Checkout Repository 27 | uses: actions/checkout@master 28 | - name: Setup Enviroment 29 | uses: shivammathur/setup-php@v2 30 | with: 31 | php-version: '7.4' 32 | - name: Speed up the packages installation process 33 | run: composer global require hirak/prestissimo 34 | - name: Install Packages 35 | run: composer install --no-dev 36 | - name: Deploy to Server 37 | uses: ngocquyhoang/deploy@laravel 38 | with: 39 | user: user 40 | host: host 41 | port: port 42 | path: path 43 | owner: owner 44 | env: 45 | DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }} 46 | ``` 47 | --------------------------------------------------------------------------------