Skip to content

Commit

Permalink
Merge 02ac149 into 1ad977a
Browse files Browse the repository at this point in the history
  • Loading branch information
nam20485 authored Oct 23, 2023
2 parents 1ad977a + 02ac149 commit bfe9276
Show file tree
Hide file tree
Showing 20 changed files with 366 additions and 26 deletions.
118 changes: 116 additions & 2 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ on:
branches: [ "development", "main", "release" ]

permissions:
contents: write
contents: write

env:
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
VCPKG_BINARY_SOURCES: 'clear;x-gha,readwrite'
# support for GH dependency graph vcpkg integration
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VCPKG_FEATURE_FLAGS: dependencygraph
ARTIFACTS_DIR: ${{ github.workspace }}/artifacts
ARTIFACTS_DIR_WIN: ${{ github.workspace }}\artifacts

jobs:
build:
Expand Down Expand Up @@ -128,7 +130,7 @@ jobs:
# if: matrix.preset == 'linux-mingw-w64-release'

#
# All platforms
# CMake Build - All platforms
#
- name: CMake Configure
run: cmake --preset ${{matrix.preset}}
Expand All @@ -138,3 +140,115 @@ jobs:

- name: CMake Test
run: ctest --preset ${{matrix.preset}} -V

#
# Artifacts
#
- name: Compress Artifacts (Linux)
if: matrix.os == 'ubuntu-22.04'
run: |
mkdir ${{env.ARTIFACTS_DIR}}
cp ./out/build/${{matrix.preset}}/OdbDesignLib/*.so ${{env.ARTIFACTS_DIR}}
cp ./out/build/${{matrix.preset}}/Utils/*.so ${{env.ARTIFACTS_DIR}}
cp ./out/build/${{matrix.preset}}/OdbDesignServer/OdbDesignServer ${{env.ARTIFACTS_DIR}}
cd ${{env.ARTIFACTS_DIR}}
zip -r ./artifacts-${{matrix.os}}.zip ./*.so ./OdbDesignServer
- name: Compress Artifacts (MacOS)
if: matrix.os == 'macos-12'
run: |
mkdir ${{env.ARTIFACTS_DIR}}
cp ./out/build/${{matrix.preset}}/OdbDesignLib/*.dylib ${{env.ARTIFACTS_DIR}}
cp ./out/build/${{matrix.preset}}/Utils/*.dylib ${{env.ARTIFACTS_DIR}}
cp ./out/build/${{matrix.preset}}/OdbDesignServer/OdbDesignServer ${{env.ARTIFACTS_DIR}}
cd ${{env.ARTIFACTS_DIR}}
zip -r ./artifacts-${{matrix.os}}.zip ./*.dylib ./OdbDesignServer
- name: Compress Artifacts (Windows)
if: matrix.os == 'windows-2022'
run: |
New-Item -ItemType Directory -Force -Path ${{env.ARTIFACTS_DIR_WIN}} -Verbose
Copy-Item -Path ".\out\build\${{matrix.preset}}\*.dll" -Destination ${{env.ARTIFACTS_DIR_WIN}} -Force -Verbose
Copy-Item -Path ".\out\build\${{matrix.preset}}\OdbDesignServer.exe" -Destination ${{env.ARTIFACTS_DIR_WIN}} -Force -Verbose
Compress-Archive -Path "${{env.ARTIFACTS_DIR_WIN}}\*.dll","${{env.ARTIFACTS_DIR_WIN}}\*.exe" -DestinationPath "${{env.ARTIFACTS_DIR_WIN}}\artifacts-${{matrix.os}}.zip" -Verbose -Force
- name: Upload Artifacts
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.os }}-artifacts
path: ${{ env.ARTIFACTS_DIR }}/artifacts-${{matrix.os}}.zip
retention-days: 1

release:
# only on pushes to the release branch
name: Create Release
needs: build
if: ${{ (github.ref_name == 'release') && github.event_name == 'push' }}
runs-on: ubuntu-22.04
permissions:
contents: write

steps:

# download the artifacts
- name: "Download artifacts"
uses: "actions/download-artifact@v2"
with:
path: ${{ github.workspace }}/artifacts

- name: Create Release Variables
run: |
ls -al ${{ github.workspace }}/artifacts
export RELEASE_VERSION="${{vars.RELEASE_VERSION_PREFIX}}.${{github.run_number}}"
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
export RELEASE_TAG="v${RELEASE_VERSION}"
echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_ENV
export RELEASE_NAME="OdbDesign ${RELEASE_TAG}"
echo "RELEASE_NAME=$RELEASE_NAME" >> $GITHUB_ENV
- name: Rename Artifacts
run: |
mv ${{ github.workspace }}/artifacts/ubuntu-22.04-artifacts/artifacts-ubuntu-22.04.zip ${{ github.workspace }}/artifacts/OdbDesign-Linux-x64.zip
mv ${{ github.workspace }}/artifacts/windows-2022-artifacts/artifacts-windows-2022.zip ${{ github.workspace }}/artifacts/OdbDesign-Windows-x64.zip
mv ${{ github.workspace }}/artifacts/macos-12-artifacts/artifacts-macos-12.zip ${{ github.workspace }}/artifacts/OdbDesign-MacOS-x64.zip
# create a release
- name: "Create GH Release"
uses: "actions/github-script@v6"
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
script: |
try {
const createResponse = await github.rest.repos.createRelease({
generate_release_notes: true,
name: process.env.RELEASE_NAME,
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: process.env.RELEASE_TAG,
target_commitish: '${{ github.ref_name }}'
});
const filenames = [
'OdbDesign-Linux-x64.zip',
'OdbDesign-Windows-x64.zip',
'OdbDesign-MacOS-x64.zip'
];
for (const filename of filenames) {
const artifactsPath = 'artifacts';
const filePath = artifactsPath +'/' + filename;
const uploadResponse = await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: createResponse.data.id,
name: filename,
data: require('fs').readFileSync(filePath),
headers: {
'content-type': 'application/zip',
'content-length': require('fs').statSync(filePath).size
}
});
}
} catch (error) {
core.setFailed(error.message);
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ build/
/.idea/workspace.xml
ssl/
Testing/Temporary/
artifacts/
/.github/workflows/create-release.js
/scripts/compress-artifacts.ps1
/scripts/compress-artifacts.sh
9 changes: 6 additions & 3 deletions Dockerfile_OdbDesignServer
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,13 @@ COPY --from=build /src/OdbDesign/out/build/linux-release/Utils/*.so .
COPY --from=build /src/OdbDesign/out/build/linux-release/OdbDesignServer/OdbDesignServer .
COPY --from=build /src/OdbDesign/out/build/linux-release/OdbDesignServer/*.so .
COPY --from=build /src/OdbDesign/out/build/linux-release/OdbDesignTests/OdbDesignTests .
# copy designs and templates directories
#COPY --from=build /src/OdbDesign/OdbDesignServer/designs ./designs
#COPY --from=build /src/OdbDesign/OdbDesignServer/templates ./templates

# copy templates directory
RUN mkdir ./templates
COPY --from=build /src/OdbDesign/OdbDesignServer/templates/* ./templates

# copy designs directory
#COPY --from=build /src/OdbDesign/OdbDesignServer/designs ./designs
# copy SSL keys in (use --mount=type=secret)

# run
Expand Down
28 changes: 28 additions & 0 deletions OdbDesignLib/OdbDesignArgs.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include "OdbDesignArgs.h"
#include "OdbDesignArgs.h"
#include "OdbDesignArgs.h"
#include "OdbDesignArgs.h"

namespace Odb::Lib
{
Expand All @@ -17,6 +20,11 @@ namespace Odb::Lib
return boolArg("use-https", DEFAULT_USE_HTTPS);
}

std::string OdbDesignArgs::sslDir() const
{
return stringArg("ssl-dir", DEFAULT_SSL_DIR);
}

std::string OdbDesignArgs::designsDir() const
{
return stringArg("designs-dir", DEFAULT_DESIGNS_DIR);
Expand All @@ -26,4 +34,24 @@ namespace Odb::Lib
{
return stringArg("templates-dir", DEFAULT_TEMPLATES_DIR);
}

bool OdbDesignArgs::help() const
{
return boolArg("help", DEFAULT_HELP);
}

std::string Odb::Lib::OdbDesignArgs::getUsageString() const
{
return "OdbDesignServer usage:\n"
"\n"
" OdbDesignServer [options]\n"
"\n"
"OPTIONS:\n"
" --port <port> Port to listen on (default: 8080)\n"
" --use-https Use HTTPS (default: false)\n"
" --ssl-dir <dir> Directory containing SSL certificate and key files (default: ./ssl)\n"
" --designs-dir <dir> Directory containing design files (default: ./designs)\n"
" --templates-dir <dir> Directory containing template files (default: ./templates)\n"
" --help Print this help message\n";
}
}
13 changes: 10 additions & 3 deletions OdbDesignLib/OdbDesignArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@ namespace Odb::Lib

int port() const;
bool useHttps() const;
std::string sslDir() const;
std::string designsDir() const;
std::string templatesDir() const;
std::string templatesDir() const;
bool help() const;

const int DEFAULT_PORT = 8888;
const bool DEFAULT_USE_HTTPS = false;
const std::string DEFAULT_DESIGNS_DIR = "designs";
const std::string DEFAULT_TEMPLATES_DIR = "templates";
const char* DEFAULT_SSL_DIR = "./ssl";
const char* DEFAULT_DESIGNS_DIR = "designs";
const char* DEFAULT_TEMPLATES_DIR = "templates";
const bool DEFAULT_HELP = false;

// Inherited via CommandLineArgs
std::string getUsageString() const override;

};
}
18 changes: 17 additions & 1 deletion OdbDesignLib/OdbServerAppBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <Logger.h>

using namespace Utils;
using namespace std::filesystem;

namespace Odb::Lib
{
Expand All @@ -17,6 +18,13 @@ namespace Odb::Lib

ExitCode Odb::Lib::OdbServerAppBase::Run()
{
// print usage and exit w/ success
if (args().help())
{
args().printUsage();
return ExitCode::Success;
}

// call base class
if (ExitCode::Success != OdbAppBase::Run()) return ExitCode::FailedInit;

Expand All @@ -30,8 +38,16 @@ namespace Odb::Lib
{
if (args().useHttps())
{
path sslDirPath(args().sslDir());
if (!exists(sslDirPath) || !is_directory(sslDirPath))
{
logerror("SSL was specified but the directory does not exist, exiting...");
return ExitCode::FailedInitSslDirDoesNotExist;
}

// enable SSL/HTTPS
m_crowApp.ssl_file("ssl/localhost.crt", "ssl/localhost.key");
m_crowApp.ssl_file((sslDirPath / SSL_CERT_FILE).string(),
(sslDirPath / SSL_KEY_FILE).string());
}
}
catch (boost::wrapexcept<boost::system::system_error>& e)
Expand Down
3 changes: 3 additions & 0 deletions OdbDesignLib/OdbServerAppBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ namespace Odb::Lib

private:
void register_routes();

static constexpr const char* SSL_CERT_FILE = "ssl.crt";
static constexpr const char* SSL_KEY_FILE = "ssl.key";
};
}
1 change: 1 addition & 0 deletions OdbDesignLib/RouteController.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Odb::Lib
{
public:
RouteController(IOdbServerApp& serverApp);
virtual ~RouteController() = default;

virtual void register_routes() = 0;

Expand Down
2 changes: 1 addition & 1 deletion OdbDesignServer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# CMakeList.txt : CMake project for OdbDesignServer
#

add_executable(OdbDesignServer "main.cpp" "Controllers/HelloWorldController.h" "Controllers/HelloWorldController.cpp" "OdbDesignServerApp.h" "OdbDesignServerApp.cpp" "Controllers/StepsEdaDataController.cpp" "Controllers/StepsEdaDataController.h" "OdbDesignServer.h" )
add_executable(OdbDesignServer "main.cpp" "Controllers/HelloWorldController.h" "Controllers/HelloWorldController.cpp" "OdbDesignServerApp.h" "OdbDesignServerApp.cpp" "Controllers/StepsEdaDataController.cpp" "Controllers/StepsEdaDataController.h" "OdbDesignServer.h" "Controllers/FileUploadController.h" "Controllers/FileUploadController.cpp")

# link to Crow
find_package(Crow CONFIG REQUIRED)
Expand Down
Loading

0 comments on commit bfe9276

Please sign in to comment.