Skip to content

Commit

Permalink
move pre/post command functionality to client (#331)
Browse files Browse the repository at this point in the history
* move command functionality to client

* fix builds

* fix linter

* update workflow
  • Loading branch information
t-aleksander authored Oct 11, 2024
1 parent 0c55e87 commit 6a453cf
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:

jobs:
lint-web:
runs-on: self-hosted
runs-on: [self-hosted, Linux, X64]

steps:
- uses: actions/checkout@v4
Expand Down
85 changes: 45 additions & 40 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Build app & create release"
name: 'Build app and create release'
on:
push:
tags:
Expand All @@ -18,9 +18,9 @@ jobs:
ref: master
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: '1.20'
go-version: '1.22'
- name: Build wireguard-go binary
run: make
env:
Expand Down Expand Up @@ -56,21 +56,33 @@ jobs:
runs-on:
- self-hosted
- Linux
- ${{ matrix.architecture }}
strategy:
fail-fast: false
matrix:
architecture: [ARM64, X64]
include:
- architecture: ARM64
deb_arch: arm64
binary_arch: aarch64
- architecture: X64
deb_arch: amd64
binary_arch: x86_64
steps:
- uses: actions/checkout@v4
with:
submodules: "recursive"
submodules: 'recursive'
- name: Write release version
run: |
VERSION=$(echo ${GITHUB_REF_NAME#v} | cut -d '-' -f1)
echo Version: $VERSION
echo "VERSION=$VERSION" >> $GITHUB_ENV
- uses: actions/setup-node@v3
with:
node-version: "20"
node-version: '20'
- uses: pnpm/action-setup@v2
with:
version: 8
version: 9
run_install: false
- name: Get pnpm store directory
shell: bash
Expand All @@ -83,13 +95,13 @@ jobs:
key: ${{ runner.os }}-pnpm-build-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-build-store-
- name: Install deps
- name: Install Node dependencies
run: pnpm install --frozen-lockfile
- uses: dtolnay/rust-toolchain@stable
- name: install linux deps
- name: Install Linux dependencies
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf libssl-dev unzip
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf libssl-dev unzip protobuf-compiler libprotobuf-dev
- name: Build packages
uses: tauri-apps/tauri-action@v0
env:
Expand All @@ -100,53 +112,44 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: src-tauri/target/release/bundle/deb/defguard-client_${{ env.VERSION }}_amd64.deb
asset_name: defguard-client_${{ env.VERSION }}_amd64.deb
asset_content_type: application/octet-stream
- name: Upload AppImage
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: src-tauri/target/release/bundle/appimage/defguard-client_${{ env.VERSION }}_amd64.AppImage
asset_name: defguard-client_${{ env.VERSION }}_amd64.AppImage
asset_path: src-tauri/target/release/bundle/deb/defguard-client_${{ env.VERSION }}_${{ matrix.deb_arch }}.deb
asset_name: defguard-client_${{ env.VERSION }}_${{ matrix.deb_arch }}.deb
asset_content_type: application/octet-stream
- name: Rename client binary
run: mv src-tauri/target/release/defguard-client defguard-client-linux-x86_64-${{ github.ref_name }}
run: mv src-tauri/target/release/defguard-client defguard-client-linux-${{ matrix.binary_arch }}-${{ github.ref_name }}
- name: Tar client binary
uses: a7ul/[email protected]
with:
command: c
files: |
defguard-client-linux-x86_64-${{ github.ref_name }}
outPath: defguard-client-linux-x86_64-${{ github.ref_name }}.tar.gz
defguard-client-linux-${{ matrix.binary_arch }}-${{ github.ref_name }}
outPath: defguard-client-linux-${{ matrix.binary_arch }}-${{ github.ref_name }}.tar.gz
- name: Upload client archive
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: defguard-client-linux-x86_64-${{ github.ref_name }}.tar.gz
asset_name: defguard-client-linux-x86_64-${{ github.ref_name }}.tar.gz
asset_path: defguard-client-linux-${{ matrix.binary_arch }}-${{ github.ref_name }}.tar.gz
asset_name: defguard-client-linux-${{ matrix.binary_arch }}-${{ github.ref_name }}.tar.gz
asset_content_type: application/octet-stream
- name: Rename daemon binary
run: mv src-tauri/target/release/defguard-service defguard-service-linux-x86_64-${{ github.ref_name }}
run: mv src-tauri/target/release/defguard-service defguard-service-linux-${{ matrix.binary_arch }}-${{ github.ref_name }}
- name: Tar daemon binary
uses: a7ul/[email protected]
with:
command: c
files: |
defguard-service-linux-x86_64-${{ github.ref_name }}
outPath: defguard-service-linux-x86_64-${{ github.ref_name }}.tar.gz
defguard-service-linux-${{ matrix.binary_arch }}-${{ github.ref_name }}
outPath: defguard-service-linux-${{ matrix.binary_arch }}-${{ github.ref_name }}.tar.gz
- name: Upload daemon archive
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: defguard-service-linux-x86_64-${{ github.ref_name }}.tar.gz
asset_name: defguard-service-linux-x86_64-${{ github.ref_name }}.tar.gz
asset_path: defguard-service-linux-${{ matrix.binary_arch }}-${{ github.ref_name }}.tar.gz
asset_name: defguard-service-linux-${{ matrix.binary_arch }}-${{ github.ref_name }}.tar.gz
asset_content_type: application/octet-stream
build-macos:
needs:
Expand All @@ -162,18 +165,18 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
submodules: "recursive"
submodules: 'recursive'
- name: Write release version
run: |
VERSION=$(echo ${GITHUB_REF_NAME#v} | cut -d '-' -f1)
echo Version: $VERSION
echo "VERSION=$VERSION" >> $GITHUB_ENV
- uses: actions/setup-node@v3
with:
node-version: "20"
node-version: '20'
- uses: pnpm/action-setup@v2
with:
version: 8
version: 9
run_install: false
- name: Get pnpm store directory
shell: bash
Expand Down Expand Up @@ -203,12 +206,12 @@ jobs:
uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
APPLE_SIGNING_IDENTITY: "Developer ID Application: TEONITE (6WD6W6WQNV)"
APPLE_SIGNING_IDENTITY: 'Developer ID Application: TEONITE (6WD6W6WQNV)'
APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
APPLE_ID: "[email protected]"
APPLE_ID: '[email protected]'
APPLE_PASSWORD: ${{ secrets.NOTARYTOOL_APP_SPECIFIC_PASSWORD }}
APPLE_TEAM_ID: "6WD6W6WQNV"
APPLE_TEAM_ID: '6WD6W6WQNV'
with:
args: --target ${{ matrix.target }} -v
- name: Build installation package
Expand Down Expand Up @@ -240,18 +243,18 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
submodules: "recursive"
submodules: 'recursive'
- name: Write release version
run: |
$env:VERSION=echo ($env:GITHUB_REF_NAME.Substring(1) -Split "-")[0]
echo Version: $env:VERSION
echo "VERSION=$env:VERSION" >> $env:GITHUB_ENV
- uses: actions/setup-node@v3
with:
node-version: "20"
node-version: '20'
- uses: pnpm/action-setup@v2
with:
version: 8
version: 9
run_install: false
- name: Get pnpm store directory
shell: bash
Expand Down Expand Up @@ -299,6 +302,7 @@ jobs:
runs-on:
- self-hosted
- Linux
- X64
steps:
- name: Write release version
run: |
Expand All @@ -323,7 +327,7 @@ jobs:
- sign-burn-engine
runs-on: windows-latest
steps:
- name: Download unsigned bundle & signed burn-engine
- name: Download unsigned bundle and signed burn-engine
uses: actions/download-artifact@v4
with:
name: unsigned-bundle-and-signed-burnengine
Expand All @@ -346,6 +350,7 @@ jobs:
runs-on:
- self-hosted
- Linux
- X64
steps:
- name: Write release version
run: |
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,41 @@ on:
- main
- dev
paths-ignore:
- "*.md"
- "LICENSE"
- '*.md'
- 'LICENSE'
pull_request:
branches:
- main
- dev
paths-ignore:
- "*.md"
- "LICENSE"
- '*.md'
- 'LICENSE'

env:
CARGO_TERM_COLOR: always

jobs:
test:
runs-on: [self-hosted, Linux]
container: rust:1.74
runs-on: [self-hosted, Linux, X64]
container: rust:1
defaults:
run:
working-directory: ./src-tauri

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: recursive
- name: Debug
run: echo ${{ github.ref_name }}
- name: Cache
uses: Swatinem/rust-cache@v2
- name: install linux deps
- name: Install required packages
run: |
apt-get update
apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf libssl-dev unzip
- name: install protobuf compiler
- name: Install protobuf compiler
run: |
PB_REL='https://github.com/protocolbuffers/protobuf/releases'
PB_VERSION='3.20.0' && curl -LO $PB_REL/download/v$PB_VERSION/protoc-$PB_VERSION-linux-x86_64.zip
Expand Down
16 changes: 12 additions & 4 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::{
service::{log_watcher::stop_log_watcher_task, proto::RemoveInterfaceRequest},
tray::configure_tray_icon,
utils::{
disconnect_interface, get_location_interface_details, get_tunnel_interface_details,
handle_connection_for_location, handle_connection_for_tunnel,
disconnect_interface, execute_command, get_location_interface_details,
get_tunnel_interface_details, handle_connection_for_location, handle_connection_for_tunnel,
},
wg_config::parse_wireguard_config,
CommonConnection, CommonConnectionInfo, CommonLocationStats, ConnectionType,
Expand Down Expand Up @@ -752,10 +752,15 @@ pub async fn delete_tunnel(tunnel_id: i64, handle: AppHandle) -> Result<(), Erro
app_state.find_and_remove_connection(tunnel_id, &ConnectionType::Tunnel)
{
debug!("Found active connection for tunnel({tunnel_id}), closing...",);
if let Some(pre_down) = &tunnel.pre_down {
debug!("Executing specified PreDown command: {pre_down}");
let _ = execute_command(pre_down);
info!("Executed specified PreDown command: {pre_down}");
}
let request = RemoveInterfaceRequest {
interface_name: connection.interface_name.clone(),
pre_down: tunnel.pre_down.clone(),
post_down: tunnel.post_up.clone(),
pre_down: None,
post_down: None,
};
client
.remove_interface(request)
Expand All @@ -768,6 +773,11 @@ pub async fn delete_tunnel(tunnel_id: i64, handle: AppHandle) -> Result<(), Erro
error!("{msg}");
Error::InternalError(msg)
})?;
if let Some(post_down) = &tunnel.post_down {
debug!("Executing specified PostDown command: {post_down}");
let _ = execute_command(post_down);
info!("Executed specified PostDown command: {post_down}");
}
info!("Connection closed and interface removed");
}
tunnel.delete(pool).await?;
Expand Down
Loading

0 comments on commit 6a453cf

Please sign in to comment.