Skip to content

Commit

Permalink
Merge pull request #2 from setoelkahfi/feature/v1.1
Browse files Browse the repository at this point in the history
v1.1
  • Loading branch information
setoelkahfi authored May 5, 2024
2 parents 6b5f73d + f30ce23 commit c94631e
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 23 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Seto

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
59 changes: 57 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,58 @@
# gapush-to-deploy
# garust-debian

GitHub Action to deploy main branch to production a la Heroku.
GitHub Action to running Rust binary on Debian Bulls Eye using SSH `rsync`.

## Supported runner

`ubuntu-20.04`

[What is my Debian in my Ubuntu?](https://askubuntu.com/a/445496/513710).

## Input

```yaml
working-directory:
description: "Working directory for the build."
required: true
binary-name:
description: "Name of the binary to run. Usually the [[bin]] value in the Cargo.toml."
required: true
ssh-user:
description: "SSH user."
required: true
ssh-host:
description: "SSH host."
required: true
ssh-private-key:
description: "SSH private key."
required: true
ssh-known-hosts:
description: "SSH known hosts."
required: true
```
## Example
```yaml
name: "Build and release"

on:
push:
branches:
- main

jobs:
build-and-release:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: setoelkahfi/garust-debian@v1
with: Install Rust stable
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
ssh-known-hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
ssh-user: ${{ secrets.SSH_USER }}
ssh-host: ${{ secrets.SSH_HOST }}
project-directory: ${{ secrets.PROJECT_DIRECTORY }}
project-name: ${{ secrets.PROJECT_NAME }}

```
42 changes: 21 additions & 21 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
name: "GitHub Action Push-to-deploy"
description: "GitHub Action to deploy main branch to production a la Heroku."
name: "GitHub Action Rust-on-Debian"
description: "GitHub Action to running Rust binary on Debian Bulls Eye."
inputs:
git-directory:
description: "Your git bare repo directory."
project-directory:
description: "Working directory for the build."
required: true
git-user:
description: "Git user. Usually deploy."
project-name:
description: "Name of the binary to run."
required: true
git-host:
description: "Git host."
ssh-user:
description: "SSH user."
required: true
ssh-host:
description: "SSH host."
required: true
ssh-private-key:
description: "SSH private key."
Expand All @@ -20,22 +23,19 @@ inputs:
runs:
using: "composite"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
depth: 0
- name: Setup remote git
run: |
git config --global user.email "${{ inputs.git-user }}@${{ inputs.git-host }}"
git config --global user.name "${{ inputs.git-user }}"
git remote add prod ${{ inputs.git-user }}@${{ inputs.git-host }}:${{ inputs.git-directory }}
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
- name: Build for release
run: cargo build --release
shell: bash
- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ inputs.ssh-private-key }}
known_hosts: ${{ inputs.ssh-known-hosts }}
- name: Push-to-deploy
run: |
git push prod HEAD:main
shell: bash
- name: rsync over SSH
run: rsync -r ./target/release/ ${{ inputs.ssh-user }}@${{ inputs.ssh-host }}:${{ inputs.project-directory }}
shell: bash
- name: Start process
run: ssh ${{ inputs.ssh-user }}@${{ inputs.ssh-host }} 'bash -s' < start.sh ./${{ inputs.project-directory }} ${{ inputs.project-name }}
shell: bash
60 changes: 60 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

echo "------------------------ STARTING DEPLOYMENT ------------------------"

# Check if the first argument is a directory
if [ ! -d "$1" ]
then
echo "😩 $1 is not a directory."
echo "🛑 Deployment failed."
exit 1
fi

# Change to working directory
cd $1

# Check if process is running

# Check if the second argument is a process
if [ -z "$2" ]
then
echo "😩 No process name provided."
echo "🛑 Deployment failed."
exit 1
fi
process_name=$2

# Check if binary exists
if [ ! -f "$process_name" ]
then
echo "😩 $process_name does not exist."
echo "🛑 Deployment failed."
exit 1
fi

echo "✅ Arguments are valid."

# Check if process is running
echo "🔍 Looking for $process_name process."
PID=$(pidof $process_name)

echo "🤨 Killing or not killing $process_name."

if [ ! -z "$PID" ]
then
echo "$process_name is running as $PID."
echo "⏳ Killing it."
kill -9 $PID
echo "✅ Killed $process_name."
else
echo "$process_name is not running."
echo "No killing needed."
fi

echo "🚀 Starting $process_name."

./$process_name > /dev/null 2>&1 &

echo "------------------------ DEPLOYMENT COMPLETED ------------------------"

exit 0

0 comments on commit c94631e

Please sign in to comment.