Skip to content

Commit

Permalink
Merge pull request #3 from janekbaraniewski/init
Browse files Browse the repository at this point in the history
init3
  • Loading branch information
janekbaraniewski authored Apr 28, 2024
2 parents 7c85d20 + 92ad54c commit 5d45c6d
Show file tree
Hide file tree
Showing 13 changed files with 248 additions and 197 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ on:
jobs:
build-and-push:
runs-on: ubuntu-latest
strategy:
matrix:
component: [server, client]

steps:
- name: Checkout code
Expand All @@ -27,11 +30,9 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and tag the Docker image
run: make build-images

- name: tag images
run: make tag-images

- name: Push Docker images to GitHub Packages
run: make push-images
- name: Build container image
run: make build-${{ matrix.component }}-image
- name: Tag container image
run: make tag-${{ matrix.component }}-image
- name: Push container image
run: make push-${{ matrix.component }}-image
103 changes: 92 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release
name: Cross-Platform and Cross-Architecture Release Build

on:
push:
Expand All @@ -7,27 +7,66 @@ on:

jobs:
build-and-release:
runs-on: ubuntu-latest
runs-on: ${{ matrix.config.os }}
strategy:
fail-fast: false
matrix:
config:
# Define combinations of operating systems and architectures
- {os: ubuntu-latest, arch: x64, server-artifact: serial_server_linux_x64, client-artifact: serial_client_linux_x64}
- {os: ubuntu-latest, arch: arm64, server-artifact: serial_server_linux_arm64, client-artifact: serial_client_linux_arm64}
- {os: windows-latest, arch: x64, server-artifact: serial_server_windows_x64.exe, client-artifact: serial_client_windows_x64.exe}
- {os: windows-latest, arch: arm64, server-artifact: serial_server_windows_arm64.exe, client-artifact: serial_client_windows_arm64.exe}
- {os: macos-latest, arch: x64, server-artifact: serial_server_mac_x64, client-artifact: serial_client_mac_x64}
- {os: macos-latest, arch: arm64, server-artifact: serial_server_mac_arm64, client-artifact: serial_client_mac_arm64}

steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies

- name: Install dependencies (Ubuntu)
if: startsWith(matrix.config.os, 'ubuntu')
run: |
sudo apt-get update
sudo apt-get install -y libboost-all-dev
- name: Install dependencies (macOS)
if: startsWith(matrix.config.os, 'macos')
run: |
brew install boost
- name: Install dependencies (Windows)
if: startsWith(matrix.config.os, 'windows')
run: |
choco install boost-msvc-14.2
- name: Set up CMake (All platforms)
uses: lukka/get-cmake@latest

- name: Configure CMake
run: |
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_ARCHITECTURE_ID=${{ matrix.config.arch }}
- name: Build
run: |
cmake -S . -B build
cmake --build build
- name: Archive Production Artifacts
cmake --build build --config Release
- name: Archive Server Production Artifacts
uses: actions/upload-artifact@v3
with:
name: binaries
path: build/
name: ${{ matrix.config.server-artifact }}
path: build/${{ matrix.config.server-artifact }}

- name: Archive Client Production Artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.config.client-artifact }}
path: build/${{ matrix.config.client-artifact }}

- name: Create Release
id: create_release
uses: actions/create-release@v1
Expand All @@ -38,12 +77,54 @@ jobs:
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
- name: Upload Release Asset

- name: Upload Server Release Asset
uses: actions/upload-release-asset@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./build/${{ matrix.config.server-artifact }}
asset_name: ${{ matrix.config.server-artifact }}
asset_content_type: application/octet-stream

- name: Upload Client Release Asset
uses: actions/upload-release-asset@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./build/serial_server
asset_name: serial_server
asset_path: ./build/${{ matrix.config.client-artifact }}
asset_name: ${{ matrix.config.client-artifact }}
asset_content_type: application/octet-stream

container-image:
runs-on: ubuntu-latest
strategy:
matrix:
component: [server, client]

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build container image
run: make build-${{ matrix.component }}-image

- name: Tag containner image
run: make tag-${{ matrix.component }}-image

- name: Push containner images
run: make push-${{ matrix.component }}-images


57 changes: 50 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,55 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ${{ matrix.config.os }}
strategy:
fail-fast: false
matrix:
config:
# Define combinations of operating systems and architectures
- {os: ubuntu-latest, arch: x64, server-artifact: serial_server_linux_x64, client-artifact: serial_client_linux_x64}
- {os: ubuntu-latest, arch: arm64, server-artifact: serial_server_linux_arm64, client-artifact: serial_client_linux_arm64}
- {os: windows-latest, arch: x64, server-artifact: serial_server_windows_x64.exe, client-artifact: serial_client_windows_x64.exe}
- {os: windows-latest, arch: arm64, server-artifact: serial_server_windows_arm64.exe, client-artifact: serial_client_windows_arm64.exe}
- {os: macos-latest, arch: x64, server-artifact: serial_server_mac_x64, client-artifact: serial_client_mac_x64}
- {os: macos-latest, arch: arm64, server-artifact: serial_server_mac_arm64, client-artifact: serial_client_mac_arm64}

steps:
- uses: actions/checkout@v3
- name: Install dependencies

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install dependencies (Ubuntu)
if: startsWith(matrix.config.os, 'ubuntu')
run: |
sudo apt-get update
sudo apt-get install -y libboost-all-dev
- name: Run tests
run: make test
docker:
- name: Install dependencies (macOS)
if: startsWith(matrix.config.os, 'macos')
run: |
brew install boost
- name: Install dependencies (Windows)
if: startsWith(matrix.config.os, 'windows')
run: |
choco install boost-msvc-14.2
- name: Set up CMake (All platforms)
uses: lukka/get-cmake@latest

- name: make build
run: |
make build
container-image:
runs-on: ubuntu-latest
strategy:
matrix:
component: [server, client]

steps:
- name: Checkout code
Expand All @@ -29,5 +65,12 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Build and tag the Docker image
run: make build-images
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build container image
run: make build-${{ matrix.component }}-image
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ target_link_libraries(logging PUBLIC
Boost::date_time
)

add_library(serial_server_lib src/logging.cpp src/server.cpp src/VirtualSerialPort.cpp) # Include VirtualSerialPort.cpp
add_library(serial_server_lib src/logging.cpp src/SerialServer.cpp src/VirtualSerialPort.cpp)
target_include_directories(serial_server_lib PUBLIC ${CMAKE_SOURCE_DIR}/include)
target_link_libraries(serial_server_lib PRIVATE
Boost::system
Expand All @@ -43,7 +43,7 @@ target_link_libraries(serial_server_lib PRIVATE
pthread
)

add_executable(serial_server src/server.cpp)
add_executable(serial_server src/SerialServer.cpp)
target_link_libraries(serial_server PRIVATE
serial_server_lib
logging
Expand All @@ -54,7 +54,7 @@ target_link_libraries(serial_server PRIVATE
Boost::date_time
)

add_executable(serial_client src/client.cpp)
add_executable(serial_client src/SerialClient.cpp)
target_link_libraries(serial_client PRIVATE
serial_server_lib
logging
Expand Down
44 changes: 29 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,52 @@ REPO = ghcr.io/janekbaraniewski/ser2net2ser
VERSION ?= latest
COMMIT_HASH ?= $(shell git rev-parse --short HEAD)

clean:
help: ## Show this help message
@echo "Usage: make [target]"
@echo ""
@echo "Available targets:"
@grep -E '^[a-zA-Z_\-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " %-30s %s\n", $$1, $$2}'

clean: ## Clean build directory
@rm -rf ${BUILD_DIR}/*

build: ## Build with cmake
build: clean
@cmake -S . -B build
@cmake --build build

test: ## Build and test
test: build
@cd build && ctest

build-images:
build-images: ## Build container images
build-images: build-server-image build-client-image

build-server-image:
@docker build . -f Dockerfile.server -t $(REPO)/server:$(COMMIT_HASH)

build-client-image:
@docker build . -f Dockerfile.client -t $(REPO)/client:$(COMMIT_HASH)

tag-images:
tag-images: ## Tag container images
tag-images: tag-server-image tag-client-image

tag-server-image:
@docker tag $(REPO)/server:$(COMMIT_HASH) $(REPO)/server:$(VERSION)

tag-client-image:
@docker tag $(REPO)/client:$(COMMIT_HASH) $(REPO)/client:$(VERSION)

push-images: tag-images

push-images: ## Push container images to registry
push-images: tag-images push-server-images push-client-images

push-server-images:
@docker push $(REPO)/server:$(COMMIT_HASH)
@docker push $(REPO)/server:$(VERSION)

push-client-images:
@docker push $(REPO)/client:$(COMMIT_HASH)
@docker push $(REPO)/client:$(VERSION)

help:
@echo "Makefile commands:"
@echo " clean - Remove build directory."
@echo " build - Build the project using cmake."
@echo " test - Run tests after building."
@echo " build-images - Build Docker images for both server and client."
@echo " tag-images - Tag Docker images with the latest or specified version."
@echo " push-images - Push Docker images to the registry."
@echo " help - Show this help message."

.PHONY: clean build test build-images tag-images push-images help
.PHONY: clean build test build-images build-server-image build-client-image tag-images tag-client-image tag-server-image push-images push-client-images push-server-images help
26 changes: 26 additions & 0 deletions include/SerialClient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef CLIENT_H
#define CLIENT_H

#include "common.hpp"
#include "VirtualSerialPort.h"

using namespace boost::asio;
using ip::tcp;
using std::string;

class SerialClient {
public:
SerialClient(const string& server_ip, unsigned short server_port, const string& vsp_name);
void run();

private:
io_service io_service_;
tcp::socket socket_;
std::array<char, 256> buffer_;
VirtualSerialPort vsp_;

void do_read_write();
};


#endif // CLIENT_H
27 changes: 27 additions & 0 deletions include/SerialServer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef SERVER_H
#define SERVER_H

#include "common.hpp"
#include "ISerialPort.h"
#include "RealSerialPort.h"

using namespace boost::asio;
using ip::tcp;
using std::string;

class SerialServer {
public:
SerialServer(io_service& io, ISerialPort& serial, tcp::acceptor& acceptor);
void run();

private:
io_service& io_service_;
ISerialPort& serial_;
tcp::acceptor& acceptor_;
tcp::socket socket_;

void start_accept();
void do_read_write();
};

#endif // SERVER_H
Loading

0 comments on commit 5d45c6d

Please sign in to comment.