-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from setoelkahfi/development
v1
- Loading branch information
Showing
3 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# garust-debian | ||
|
||
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 }} | ||
|
||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: "GitHub Action Rust-on-Debian" | ||
description: "GitHub Action to running Rust binary on Debian Bulls Eye." | ||
inputs: | ||
project-directory: | ||
description: "Working directory for the build." | ||
required: true | ||
project-name: | ||
description: "Name of the binary to run." | ||
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 | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- 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: 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 |
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
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 |