Skip to content

Commit

Permalink
feat: added two agent packages (msi and pkg) to install agent binary …
Browse files Browse the repository at this point in the history
…to windows and macOS via local package manager
  • Loading branch information
asdek committed Jun 4, 2023
1 parent a715f39 commit 74890ee
Show file tree
Hide file tree
Showing 26 changed files with 750 additions and 15 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/build-docker-vxres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,45 @@ jobs:
- uses: actions/download-artifact@v3
with:
name: agent_windows
- uses: actions/download-artifact@v3
with:
name: agent_deb
path: agent_deb
- uses: actions/download-artifact@v3
with:
name: agent_rpm
path: agent_rpm
- uses: actions/download-artifact@v3
with:
name: agent_pkg
path: agent_pkg
- uses: actions/download-artifact@v3
with:
name: agent_msi
path: agent_msi
- uses: actions/download-artifact@v3
with:
name: decode_environment
- name: prepare files
run: |
mv build/package/agent/Dockerfile_cross build/package/agent/Dockerfile
mkdir build/package/agent/_tmp
# restore agent binaries
cp -r agent/_tmp/* build/package/agent/_tmp
# restore agent deb and rpm packages
cp agent_rpm/vxagent-*_i386.rpm build/package/agent/_tmp/linux/386/vxagent.rpm
cp agent_rpm/vxagent-*_amd64.rpm build/package/agent/_tmp/linux/amd64/vxagent.rpm
cp agent_deb/vxagent-*_i386.deb build/package/agent/_tmp/linux/386/vxagent.deb
cp agent_deb/vxagent-*_amd64.deb build/package/agent/_tmp/linux/amd64/vxagent.deb
# restore agent pkg package
cp agent_pkg/vxagent-*_amd64.pkg build/package/agent/_tmp/darwin/amd64/vxagent.pkg
# restore agent msi packages
cp agent_msi/vxagent-*_x86.msi build/package/agent/_tmp/windows/386/vxagent.msi
cp agent_msi/vxagent-*_x64.msi build/package/agent/_tmp/windows/amd64/vxagent.msi
# set executable flag for linux and macOS binaries
chmod +x build/package/agent/_tmp/linux/*/vxagent
chmod +x build/package/agent/_tmp/darwin/*/vxagent
# enumerate restored files
ls -R build/package/agent/_tmp
- name: Docker build vxres
uses: ./.github/actions/docker_build
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/build-installer-vxagent-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ jobs:
mkdir build/package/agent/_tmp
cp -r agent/_tmp/* build/package/agent/_tmp
ls -R build/package/agent/_tmp
- name: Build installer
- name: Build Linux installer
run: |
cd build/package/agent
chmod +x build-install-linux.sh
./build-install-linux.sh
- name: Upload result for deb installer
uses: actions/upload-artifact@v3
with:
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/build-installer-vxagent-osx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: VXAgent installer build

on: workflow_call

jobs:
build_installer_osx:
name: Installer build
environment:
name: production
runs-on: macos-latest

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/download-artifact@v3
with:
name: agent_osx
- uses: actions/download-artifact@v3
with:
name: decode_environment
- name: prepare files
run: |
mkdir build/package/agent/_tmp
cp -r agent/_tmp/* build/package/agent/_tmp
ls -R build/package/agent/_tmp
shell: bash
- name: Build macOS installer
run: |
cd build/package/agent
chmod +x build-install-osx.sh
VERSION=$(cat _tmp/version) ./build-install-osx.sh
cp install_osx/vxagent-*_amd64.pkg _tmp/darwin/amd64/vxagent.pkg
- name: Upload result for pkg installer
uses: actions/upload-artifact@v3
with:
name: agent_pkg
path: |
build/package/agent/install_osx/*.pkg
44 changes: 44 additions & 0 deletions .github/workflows/build-installer-vxagent-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: VXAgent installer build

on: workflow_call

jobs:
build_installer_windows:
name: Installer build
environment:
name: production
runs-on: windows-2019

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/download-artifact@v3
with:
name: agent_windows
- uses: actions/download-artifact@v3
with:
name: decode_environment
- name: prepare files
run: |
mkdir build/package/agent/_tmp
cp -r agent/_tmp/* build/package/agent/_tmp
ls -R build/package/agent/_tmp
shell: bash
- name: Set path for heat.exe and light.exe
run: echo "$WIX\\bin" >>$GITHUB_PATH
shell: bash
- name: Build Windows installer
run: |
cd build/package/agent
pwsh -ExecutionPolicy Bypass -File build.ps1 packages.json vxagent
mkdir install_windows
cp dist/*.msi install_windows/
- name: Upload result for msi installer
uses: actions/upload-artifact@v3
with:
name: agent_msi
path: |
build/package/agent/install_windows/*.msi
12 changes: 11 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
build_docker_vxres:
uses: vxcontrol/soldr/.github/workflows/build-docker-vxres.yml@master
if: github.ref_name == 'master' || startsWith(github.ref, 'refs/tags')
needs: [ build_agent_linux, build_agent_windows, build_agent_osx ]
needs: [ build_installer_vxagent_linux, build_installer_vxagent_windows, build_installer_vxagent_osx ]
secrets: inherit
build_docker_vxserver:
uses: vxcontrol/soldr/.github/workflows/build-docker-vxserver.yml@master
Expand All @@ -82,3 +82,13 @@ jobs:
if: github.ref_name == 'master' || startsWith(github.ref, 'refs/tags')
needs: build_agent_linux
secrets: inherit
build_installer_vxagent_windows:
uses: vxcontrol/soldr/.github/workflows/build-installer-vxagent-windows.yml@master
if: github.ref_name == 'master' || startsWith(github.ref, 'refs/tags')
needs: build_agent_windows
secrets: inherit
build_installer_vxagent_osx:
uses: vxcontrol/soldr/.github/workflows/build-installer-vxagent-osx.yml@master
if: github.ref_name == 'master' || startsWith(github.ref, 'refs/tags')
needs: build_agent_osx
secrets: inherit
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 VXControl SOLDR
Copyright (c) 2023 VXControl SOLDR

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion build/package/agent/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN mkdir -p /opt/vxagent/bin && \

COPY build/package/agent/preparing.sh /opt/vxagent/bin/
COPY build/package/agent/_tmp/version /opt/vxagent/bin/
COPY build/package/agent/_tmp/linux/amd64/vxagent /opt/vxagent/bin/
COPY build/package/agent/_tmp/linux/amd64/vxbundle /opt/vxagent/bin/vxagent
COPY build/package/agent/_tmp/deps/libraries_amd64.tar.gz /opt/vxagent/deps/

RUN mkdir -p /usr/lib/vxagent && \
Expand Down
4 changes: 0 additions & 4 deletions build/package/agent/build-install-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ md5deep -r vxagent/opt/vxcontrol/vxagent > vxagent/DEBIAN/md5sums
chmod -R 755 vxagent/DEBIAN

fakeroot dpkg-deb -Zxz --build vxagent vxagent-${VERSION}_${arch}.deb || exit 1
cp vxagent-${VERSION}_${arch}.deb _tmp/linux/386/vxagent.deb

echo "Done create deb $arch"

Expand Down Expand Up @@ -66,7 +65,6 @@ md5deep -r vxagent/opt/vxcontrol/vxagent > vxagent/DEBIAN/md5sums
chmod -R 755 vxagent/DEBIAN

fakeroot dpkg-deb -Zxz --build vxagent vxagent-${VERSION}_${arch}.deb || exit 1
cp vxagent-${VERSION}_${arch}.deb _tmp/linux/amd64/vxagent.deb

echo "Done create deb $arch"

Expand All @@ -83,7 +81,6 @@ cp vxagent.service ~/rpmbuild/SOURCES/vxagent/unit/

rpmbuild -bb ./rpm_$arch.spec --target i386
cp ~/rpmbuild/RPMS/i386/* install_linux/vxagent-${VERSION}_i386.rpm
cp install_linux/vxagent-${VERSION}_i386.rpm _tmp/linux/386/vxagent.rpm

arch="amd64"
rm -rf ~/rpmbuild/SOURCES/* || true
Expand All @@ -95,4 +92,3 @@ cp vxagent.service ~/rpmbuild/SOURCES/vxagent/unit/
eval "echo \"$(cat RPM/rpm.spec)\"" > rpm_$arch.spec
rpmbuild -bb ./rpm_$arch.spec --target amd64
cp ~/rpmbuild/RPMS/amd64/* install_linux/vxagent-${VERSION}_amd64.rpm
cp install_linux/vxagent-${VERSION}_amd64.rpm _tmp/linux/amd64/vxagent.rpm
137 changes: 137 additions & 0 deletions build/package/agent/build-install-osx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#!/bin/bash
set -e

TARGET_DIRECTORY="target"
PRODUCT="vxagent"
OUTPUT_PATH="install_osx"
export VERSION=${VERSION/v/}
export VERSION=${VERSION%-*}


log_info() {
echo "${LOG_PREFIX}[INFO]" $1
}

log_warn() {
echo "${LOG_PREFIX}[WARN]" $1
}

log_error() {
echo "${LOG_PREFIX}[ERROR]" $1
}

deleteInstallationDirectory() {
log_info "Cleaning $TARGET_DIRECTORY directory."
rm -rf $TARGET_DIRECTORY

if [[ $? != 0 ]]; then
log_error "Failed to clean $TARGET_DIRECTORY directory" $?
exit 1
fi
}

createInstallationDirectory() {
if [ -d ${TARGET_DIRECTORY} ]; then
deleteInstallationDirectory
fi
mkdir -p $TARGET_DIRECTORY

if [[ $? != 0 ]]; then
log_error "Failed to create $TARGET_DIRECTORY directory" $?
exit 1
fi
}

deleteOutputPath() {
log_info "Cleaning ${OUTPUT_PATH} directory."
rm -rf ${OUTPUT_PATH}

if [[ $? != 0 ]]; then
log_error "Failed to clean ${OUTPUT_PATH} directory" $?
exit 1
fi
}

createOutputPath() {
if [ -d ${OUTPUT_PATH} ]; then
deleteOutputPath
fi
mkdir -p ${OUTPUT_PATH}

if [[ $? != 0 ]]; then
log_error "Failed to create $TARGET_DIRECTORY directory" $?
exit 1
fi

}

copyDarwinDirectory() {
createInstallationDirectory
createOutputPath
cp -r darwin ${TARGET_DIRECTORY}/
chmod -R 755 ${TARGET_DIRECTORY}/darwin
}

copyBuildDirectory() {
sed -i '' -e 's/__VERSION__/'${VERSION}'/g;s/__PRODUCT__/'${PRODUCT}'/g' ${TARGET_DIRECTORY}/darwin/scripts/postinstall
sed -i '' -e 's/__VERSION__/'${VERSION}'/g;s/__PRODUCT__/'${PRODUCT}'/g' ${TARGET_DIRECTORY}/darwin/Distribution
sed -i '' -e 's/__VERSION__/'${VERSION}'/g;s/__PRODUCT__/'${PRODUCT}'/g' ${TARGET_DIRECTORY}/darwin/Resources/*.html

rm -rf ${TARGET_DIRECTORY}/darwinpkg
mkdir -p ${TARGET_DIRECTORY}/darwinpkg

#Copy product to /Library/PRODUCT
mkdir -p ${TARGET_DIRECTORY}/darwinpkg/Library/${PRODUCT}
log_info "Try signing executable file"
cp -a _tmp/darwin/amd64/vxagent ${TARGET_DIRECTORY}/darwinpkg/Library/${PRODUCT}
chmod -R 755 ${TARGET_DIRECTORY}/darwinpkg/Library/${PRODUCT}

rm -rf ${TARGET_DIRECTORY}/package
mkdir -p ${TARGET_DIRECTORY}/package
chmod -R 755 ${TARGET_DIRECTORY}/package

rm -rf ${TARGET_DIRECTORY}/pkg
mkdir -p ${TARGET_DIRECTORY}/pkg
chmod -R 755 ${TARGET_DIRECTORY}/pkg
}

function buildPackage() {
log_info "Application installer package building started.(1/2)"
pkgbuild --identifier org.${PRODUCT}.${VERSION} \
--version ${VERSION} \
--scripts ${TARGET_DIRECTORY}/darwin/scripts \
--root ${TARGET_DIRECTORY}/darwinpkg \
${TARGET_DIRECTORY}/package/${PRODUCT}.pkg >/dev/null 2>&1
}

function buildProduct() {
log_info "Application installer product building started.(2/2)"
productbuild --distribution ${TARGET_DIRECTORY}/darwin/Distribution \
--resources ${TARGET_DIRECTORY}/darwin/Resources \
--package-path ${TARGET_DIRECTORY}/package \
${TARGET_DIRECTORY}/pkg/$1 >/dev/null 2>&1
}

function createInstaller() {
log_info "Application installer generation process started.(2 Steps)"
buildPackage
buildProduct ${PRODUCT}-${VERSION}_amd64.pkg
mv ${TARGET_DIRECTORY}/pkg/${PRODUCT}-${VERSION}_amd64.pkg ${OUTPUT_PATH}/${PRODUCT}-${VERSION}_amd64.pkg
log_info "Application installer generation steps finished."
}

function createUninstaller() {
cp darwin/Resources/uninstall.sh ${TARGET_DIRECTORY}/darwinpkg/Library/${PRODUCT}
sed -i '' -e "s/__VERSION__/${VERSION}/g;s/__PRODUCT__/${PRODUCT}/g" "${TARGET_DIRECTORY}/darwinpkg/Library/${PRODUCT}/uninstall.sh"
}


log_info "Installer generating process started."

copyDarwinDirectory
copyBuildDirectory
createUninstaller
createInstaller

log_info "Installer generating process finished"
exit 0
Loading

0 comments on commit 74890ee

Please sign in to comment.