-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad74f07
commit 7a55b9c
Showing
7 changed files
with
223 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,78 @@ | ||
name: Deploy App | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
tag: | ||
description: 'Tag to deploy' | ||
required: true | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
env: | ||
HOST: ${{ secrets.DEPLOY_SSH_USER }}@${{ secrets.DEPLOY_SSH_HOST }} | ||
DEPLOY_DIRECTORY: /root/apps/shutdown-from-browser | ||
CONFIG_PATH: /root/apps/shutdown-from-browser/config/config.prod.yaml | ||
ENV_FILE_PATH: /root/apps/shutdown-from-browser/config.env | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: ${{ github.event.inputs.tag }} | ||
- name: Check if tag exists | ||
run: | | ||
git fetch --all --tags | ||
if ! git tag | grep -q "^${{ github.event.inputs.tag }}$"; then | ||
echo "error: Tag '${{ github.event.inputs.tag }}' not found" | ||
exit 1 | ||
fi | ||
- name: Use Node.js 16 | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16 | ||
- run: | | ||
cd ./web | ||
npm ci | ||
npm install --legacy-peer-deps | ||
npm run build | ||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.20.2 | ||
- name: Build app | ||
run: | | ||
go mod download | ||
CGO_ENABLED=0 GOOS=linux go build -ldflags "-w" -a -o sfb ./cmd/shutdown-from-browser | ||
- name: Deploy to VM | ||
run: | | ||
sudo apt-get install -y ssh rsync | ||
echo "$DEPLOY_SSH_KEY" > deploy_key.pem | ||
chmod 600 deploy_key.pem | ||
ssh -i deploy_key.pem -o StrictHostKeyChecking=no ${{ env.HOST }} "mkdir -p ${{ env.DEPLOY_DIRECTORY }}" | ||
rsync -avz -e 'ssh -i deploy_key.pem -o StrictHostKeyChecking=no' --exclude='.git' ./ ${{ env.HOST }}:${{ env.DEPLOY_DIRECTORY }} | ||
env: | ||
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }} | ||
- name: Remove old systemd service file | ||
run: | | ||
ssh -i deploy_key.pem -o StrictHostKeyChecking=no ${{ env.HOST }} "rm -f /etc/systemd/system/shutdown-from-browser.service" | ||
- name: List workspace contents | ||
run: | | ||
echo "Listing deployments folder contents:" | ||
ls -la ${{ github.workspace }}/deployments | ||
- name: Create environment file on server | ||
run: | | ||
ssh -i deploy_key.pem -o StrictHostKeyChecking=no ${{ env.HOST }} "\ | ||
touch ${{ env.ENV_FILE_PATH }} && \ | ||
chmod 600 ${{ env.ENV_FILE_PATH }} && \ | ||
echo 'CONFIG_PATH=${{ env.CONFIG_PATH }}' > ${{ env.ENV_FILE_PATH }} && \ | ||
- name: Copy systemd service file | ||
run: | | ||
scp -i deploy_key.pem -o StrictHostKeyChecking=no ${{ github.workspace }}/deployments/shutdown-from-browser.service ${{ env.HOST }}:/tmp/shutdown-from-browser.service | ||
ssh -i deploy_key.pem -o StrictHostKeyChecking=no ${{ env.HOST }} "mv /tmp/shutdown-from-browser.service /etc/systemd/system/shutdown-from-browser.service" | ||
- name: Start application | ||
run: | | ||
ssh -i deploy_key.pem -o StrictHostKeyChecking=no ${{ env.HOST }} "systemctl daemon-reload && systemctl restart shutdown-from-browser.service" |
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,55 @@ | ||
name: Go Run Linter | ||
on: | ||
push: | ||
branches: | ||
- master | ||
- main | ||
pull_request: | ||
|
||
permissions: | ||
contents: read | ||
# Optional: allow read access to pull request. Use with `only-new-issues` option. | ||
# pull-requests: read | ||
|
||
jobs: | ||
golangci: | ||
name: lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.20' | ||
cache: false | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v3 | ||
with: | ||
# Require: The version of golangci-lint to use. | ||
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version. | ||
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit. | ||
version: v1.53 | ||
|
||
# Optional: working directory, useful for monorepos | ||
# working-directory: somedir | ||
|
||
# Optional: golangci-lint command line arguments. | ||
# | ||
# Note: By default, the `.golangci.yml` file should be at the root of the repository. | ||
# The location of the configuration file can be changed by using `--config=` | ||
# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0 | ||
|
||
# Optional: show only new issues if it's a pull request. The default value is `false`. | ||
# only-new-issues: true | ||
|
||
# Optional: if set to true, then all caching functionality will be completely disabled, | ||
# takes precedence over all other caching options. | ||
# skip-cache: true | ||
|
||
# Optional: if set to true, then the action won't cache or restore ~/go/pkg. | ||
# skip-pkg-cache: true | ||
|
||
# Optional: if set to true, then the action won't cache or restore ~/.cache/go-build. | ||
# skip-build-cache: true | ||
|
||
# Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'. | ||
# install-mode: "goinstall" |
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,21 @@ | ||
name: Go Run Test | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.20.2' | ||
|
||
- name: Build | ||
run: go build -v ./... | ||
|
||
- name: Unit tests | ||
run: go test -v ./... |
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,30 @@ | ||
name: React Run Linter | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- main | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node_version: [16] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js ${{ matrix.node_version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node_version: ${{ matrix.node_version }} | ||
|
||
- name: run eslint | ||
run: | | ||
cd ./web | ||
npm install | ||
npm rebuild node-sass | ||
npm run lint |
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,24 @@ | ||
<p align="center"> | ||
<img height="450px" alt="Shows an illustrated sun in light mode and a moon with stars in dark mode." src="https://github.com/korovindenis/shutdown-from-browser/raw/master/.github/img/homer.png"> | ||
</p> | ||
|
||
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/korovindenis/shutdown-from-browser) | ||
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/korovindenis/shutdown-from-browser) | ||
![GitHub](https://img.shields.io/github/license/korovindenis/shutdown-from-browser) | ||
|
||
The service for linux allowing you to manage the power of the system (server or PC) from the web browser or through the rest requests to api | ||
|
||
#### The application allows: | ||
- to restart the system | ||
- to turn off the system | ||
- to turn off the system according to the scheduler (for example, after n-hours) | ||
- through the rest api to know or set the time for the automatic shutdown or restart the system immediately | ||
|
||
The configuration file configures the port on which the application will run and the logging level | ||
With the help of the Makefile you can install the application as a linux service | ||
|
||
#### Installation | ||
```sh | ||
Make build-app | ||
Make install | ||
``` |
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,15 @@ | ||
[Unit] | ||
Description=Go PC Info | ||
After=network.target | ||
|
||
[Service] | ||
User=root | ||
WorkingDirectory=/root/apps/shutdown-from-browser | ||
ExecStart=/root/apps/shutdown-from-browser/sfb | ||
Restart=always | ||
RestartSec=10 | ||
StandardOutput=inherit | ||
EnvironmentFile=/root/apps/shutdown-from-browser/config.env | ||
|
||
[Install] | ||
WantedBy=multi-user.target |