diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index c88bcfe..ed4399b 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -4,6 +4,20 @@ ARG VARIANT="bullseye" FROM mcr.microsoft.com/vscode/devcontainers/cpp:0-${VARIANT} +# product arguments +ARG ENV="production" +ARG NAME="connector" + +# default arguments for build +ARG WORK_DIR="/connector" +ARG BUILD_DIR="build" +ARG DIST_DIR="dist" + +# default arguments for application +ARG REMOTE_IP_ADDRESS="198.41.0.4" +ARG REMOTE_PORT="53" +ARG CLIENT_MESSAGE="0" + # [Optional] Install CMake version different from what base image has already installed. # CMake reinstall choices: none, 3.21.5, 3.22.2, or versions from https://cmake.org/download/ ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="none" @@ -30,4 +44,20 @@ RUN sudo apt-get -y install ninja-build RUN sudo apt-get -y install libboost-all-dev # install Ruby Gemfile -RUN sudo gem install bundler \ No newline at end of file +RUN sudo gem install bundler + +# set environments + +# product environment +ENV ENV=${ENV} +ENV NAME=${NAME} + +# default envionment for build +ENV WORK_DIR=${WORK_DIR} +ENV BUILD_DIR=${BUILD_DIR} +ENV DIST_DIR=${DIST_DIR} + +# default environment for application +ENV REMOTE_IP_ADDRESS=${REMOTE_IP_ADDRESS} +ENV REMOTE_PORT=${REMOTE_PORT} +ENV CLIENT_MESSAGE=${CLIENT_MESSAGE} \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 1a6bfae..ac34c77 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -7,7 +7,19 @@ // Update 'VARIANT' to pick an Debian / Ubuntu OS version: debian-11, debian-10, ubuntu-22.04, ubuntu-20.04, ubuntu-18.04 // Use Debian 11, Ubuntu 18.04 or Ubuntu 22.04 on local arm64/Apple Silicon "args": { - "VARIANT": "debian-11" + // # os + "VARIANT": "debian-11", + // # product + "ENV": "development", + "NAME": "connector", + // # build + "WORK_DIR": "/connector", + "BUILD_DIR": "build", + "DIST_DIR": "dist", + // # application + "REMOTE_IP_ADDRESS": "198.41.0.4", + "REMOTE_PORT": "53", + "CLIENT_MESSAGE": "0" } }, "runArgs": [ @@ -21,12 +33,13 @@ "extensions": [ "ms-vscode.cpptools", "ms-vscode.cmake-tools", - "alexkrechik.cucumberautocomplete" + "alexkrechik.cucumberautocomplete", + "ms-azuretools.vscode-docker" ], // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "chmod +x ./install.sh && ./install.sh", + // "postCreateCommand": "chmod +x ./install.sh && ./install.sh", // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. "remoteUser": "vscode" } \ No newline at end of file diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c795b05 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +build \ No newline at end of file diff --git a/.env b/.env new file mode 100644 index 0000000..824e4ae --- /dev/null +++ b/.env @@ -0,0 +1,14 @@ +# product +ENV="production" +NAME="connector" +CONTAINER="linux" + +# build +WORK_DIR="/connector" +BUILD_DIR="build" +DIST_DIR="dist" + +# application +REMOTE_IP_ADDRESS="198.41.0.4" +REMOTE_PORT="53" +CLIENT_MESSAGE="-1" \ No newline at end of file diff --git a/Dockerfile.linux b/Dockerfile.linux new file mode 100644 index 0000000..3a86cec --- /dev/null +++ b/Dockerfile.linux @@ -0,0 +1,58 @@ +# base operation system image +FROM ubuntu:latest AS production + +# Metadata indicating an image maintainer. +LABEL maintainer="Azmi ŞAHİN " + +# product arguments +ARG ENV="production" +ARG NAME="connector" + +# default arguments for build +ARG WORK_DIR="/connector" +ARG BUILD_DIR="build" +ARG DIST_DIR="dist" + +# default arguments for application +ARG REMOTE_IP_ADDRESS="198.41.0.4" +ARG REMOTE_PORT="53" +ARG CLIENT_MESSAGE="0" + +# product environment +ENV ENV=${ENV} +ENV NAME=${NAME} + +# default envionment for build +ENV WORK_DIR=${WORK_DIR} +ENV BUILD_DIR=${BUILD_DIR} +ENV DIST_DIR=${DIST_DIR} + +# default environment for application +ENV REMOTE_IP_ADDRESS=${REMOTE_IP_ADDRESS} +ENV REMOTE_PORT=${REMOTE_PORT} +ENV CLIENT_MESSAGE=${CLIENT_MESSAGE} + +# make the 'application' folder the current working directory +WORKDIR ${WORK_DIR} + +# copy project file the working directory +COPY . . + +# install project dependencies +RUN apt-get update +RUN apt-get -y install build-essential +RUN apt-get -y install clang +RUN apt-get -y install cmake + +# build +RUN mkdir ${BUILD_DIR} && \ + cd ${BUILD_DIR} && \ + cmake .. &&\ + make &&\ + mkdir ${DIST_DIR} && \ + mkdir ${DIST_DIR}_test && \ + cp ./${NAME} ${DIST_DIR} && \ + cp ./${NAME}_test ${DIST_DIR}_test + +# test +CMD ["bash", "-c", "${WORK_DIR}/${BUILD_DIR}/${DIST_DIR}_test/${NAME}_test ${REMOTE_IP_ADDRESS} ${REMOTE_PORT} \"${CLIENT_MESSAGE}\""] \ No newline at end of file diff --git a/Dockerfile.windows b/Dockerfile.windows new file mode 100644 index 0000000..76afe27 --- /dev/null +++ b/Dockerfile.windows @@ -0,0 +1,58 @@ +# base operation system image +FROM mcr.microsoft.com/windows/servercore:ltsc2019 as production + +# Metadata indicating an image maintainer. +LABEL maintainer="Azmi ŞAHİN " + +# product arguments +ARG ENV="production" +ARG NAME="connector" + +# default arguments for build +ARG WORK_DIR="/connector" +ARG BUILD_DIR="build" +ARG DIST_DIR="dist" + +# default arguments for application +ARG REMOTE_IP_ADDRESS="198.41.0.4" +ARG REMOTE_PORT="53" +ARG CLIENT_MESSAGE="0" + +# product environment +ENV ENV=${ENV} +ENV NAME=${NAME} + +# default envionment for build +ENV WORK_DIR=${WORK_DIR} +ENV BUILD_DIR=${BUILD_DIR} +ENV DIST_DIR=${DIST_DIR} + +# default environment for application +ENV REMOTE_IP_ADDRESS=${REMOTE_IP_ADDRESS} +ENV REMOTE_PORT=${REMOTE_PORT} +ENV CLIENT_MESSAGE=${CLIENT_MESSAGE} + +# make the 'application' folder the current working directory +WORKDIR ${WORK_DIR} + +# copy project file the working directory +COPY . . + +# install project dependencies +# update +# install build tools +# install clang +# install cmake + +# build +RUN mkdir %BUILD_DIR% && \ + cd %BUILD_DIR% && \ + echo cmake .. &&\ + echo make &&\ + mkdir %DIST_DIR% && \ + mkdir %DIST_DIR%_test && \ + echo copy ./%NAME%.exe %DIST_DIR% && \ + echo copy ./%NAME%_test.exe %DIST_DIR%_test.exe + +# test +RUN echo %WORK_DIR%/%BUILD_DIR%/%DIST_DIR%_test/%NAME%_test.exe %REMOTE_IP_ADDRESS% %REMOTE_PORT% "%CLIENT_MESSAGE%" \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..9dab5e3 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,39 @@ +version: '3.8' +services: + application: + build: + context: . + # load operating system container + dockerfile: Dockerfile.${CONTAINER} + args: + # build + NAME: ${NAME} + WORK_DIR: ${WORK_DIR} + BUILD_DIR: ${BUILD_DIR} + DIST_DIR: ${DIST_DIR} + + # application + REMOTE_IP_ADDRESS: ${REMOTE_IP_ADDRESS} + REMOTE_PORT: ${REMOTE_PORT} + CLIENT_MESSAGE: ${CLIENT_MESSAGE} + labels: + com.azmisahin.description: ${NAME} + com.azmisahin.department: "DEVOPS" + # stage + target: ${ENV} + container_name: ${NAME}-${CONTAINER} + environment: + # build + NAME: ${NAME} + WORK_DIR: ${WORK_DIR} + BUILD_DIR: ${BUILD_DIR} + DIST_DIR: ${DIST_DIR} + + # application + REMOTE_IP_ADDRESS: ${REMOTE_IP_ADDRESS} + REMOTE_PORT: ${REMOTE_PORT} + CLIENT_MESSAGE: ${CLIENT_MESSAGE} + networks: + default: null + restart: "no" + tty: true diff --git a/install.sh b/install.sh deleted file mode 100644 index f7a24bb..0000000 --- a/install.sh +++ /dev/null @@ -1,24 +0,0 @@ -#/** -# * @file install.sh -# * @author Azmi ŞAHİN (azmisahin@outlook.com) -# * @brief emulation of risc-based architectures with a cisc architecture. -# * @version 0.1 -# * @date 2022-05-02 -# * -# * @copyright Copyright (c) 2022 -# */ - -echo ruby package install -bundle install - -echo gcc version -gcc --version - -echo ruby version -ruby --version - -echo gem version -gem --version - -echo cucumber version -cucumber --version \ No newline at end of file diff --git a/src/Sockets/IpAddress.h b/src/Sockets/IpAddress.h index 1f7af47..655c1f3 100644 --- a/src/Sockets/IpAddress.h +++ b/src/Sockets/IpAddress.h @@ -11,8 +11,10 @@ #ifndef IPADDRESS_H #define IPADDRESS_H -#define A_ROOT_SERVER_NET "198.41.0.4" -#define DNS_PORT 53 +#include +// make source codes suitable for devops production environment. +#define A_ROOT_SERVER_NET std::getenv("REMOTE_IP_ADDRESS") +#define DNS_PORT std::getenv("REMOTE_PORT") /** * module dependencies diff --git a/tests/Sockets/src/SocketBase_Spec.cpp b/tests/Sockets/src/SocketBase_Spec.cpp index ac147c7..fe81d59 100644 --- a/tests/Sockets/src/SocketBase_Spec.cpp +++ b/tests/Sockets/src/SocketBase_Spec.cpp @@ -13,6 +13,10 @@ #include "../../../src/Sockets/IpAddress.h" #include "../../TestTool.h" +// define test environment +char *REMOTE_IP_ADDRESS = A_ROOT_SERVER_NET; +int REMOTE_PORT = strtol(DNS_PORT, NULL, 10); + bool Constractor_AddressFamiliySpec() { SocketBase instance(2, 1, 0); @@ -49,8 +53,6 @@ bool Constractor_ProtocolTypeSpec() bool CreateSpec() { SocketBase instance(2, 1, 0); - char *hostName = (char *)A_ROOT_SERVER_NET; - int portNumber = DNS_PORT; bool expected = 1; bool actual = instance.Id(); @@ -61,10 +63,10 @@ bool CreateSpec() bool ConnectSpec() { - SocketBase instance(2, 1, 0); + char *hostName = REMOTE_IP_ADDRESS; + int portNumber = REMOTE_PORT; - char *hostName = (char *)A_ROOT_SERVER_NET; - int portNumber = DNS_PORT; + SocketBase instance(2, 1, 0); SocketStatus expected = SocketStatus::Connected; SocketStatus actual = instance.Connect(hostName, portNumber); @@ -75,9 +77,10 @@ bool ConnectSpec() bool SendSpec() { + char *hostName = REMOTE_IP_ADDRESS; + int portNumber = REMOTE_PORT; + SocketBase instance(2, 1, 0); - char *hostName = (char *)A_ROOT_SERVER_NET; - int portNumber = DNS_PORT; char *message = (char *)"00000001"; @@ -92,9 +95,10 @@ bool SendSpec() bool DownSpec() { + char *hostName = REMOTE_IP_ADDRESS; + int portNumber = REMOTE_PORT; + SocketBase instance(2, 1, 0); - char *hostName = (char *)A_ROOT_SERVER_NET; - int portNumber = DNS_PORT; char *message = (char *)"00000001"; @@ -110,9 +114,10 @@ bool DownSpec() bool ReceiveSpec() { + char *hostName = REMOTE_IP_ADDRESS; + int portNumber = REMOTE_PORT; + SocketBase instance(2, 1, 0); - char *hostName = (char *)A_ROOT_SERVER_NET; - int portNumber = DNS_PORT; char *message = (char *)"00000001"; @@ -128,9 +133,10 @@ bool ReceiveSpec() bool IdSpec() { + char *hostName = REMOTE_IP_ADDRESS; + int portNumber = REMOTE_PORT; + SocketBase instance(2, 1, 0); - char *hostName = (char *)A_ROOT_SERVER_NET; - int portNumber = DNS_PORT; bool expected = 1; bool actual = instance.Id(); diff --git a/tests/Sockets/src/SocketBase_Test.cpp b/tests/Sockets/src/SocketBase_Test.cpp index 02da620..b429916 100644 --- a/tests/Sockets/src/SocketBase_Test.cpp +++ b/tests/Sockets/src/SocketBase_Test.cpp @@ -15,6 +15,10 @@ #define BOOST_TEST_MODULE SocketBaseTest #include +// define test environment +char *REMOTE_IP_ADDRESS = A_ROOT_SERVER_NET; +int REMOTE_PORT = strtol(DNS_PORT, NULL, 10); + BOOST_AUTO_TEST_SUITE(SocketBase_Suit) BOOST_AUTO_TEST_CASE(Constractor_AddressFamiliy) { @@ -48,10 +52,10 @@ BOOST_AUTO_TEST_CASE(Constractor_ProtocolType) BOOST_AUTO_TEST_CASE(Connect) { - SocketBase instance(2, 1, 0); + char *hostName = REMOTE_IP_ADDRESS; + int portNumber = REMOTE_PORT; - char *hostName = A_ROOT_SERVER_NET; - int portNumber = DNS_PORT; + SocketBase instance(2, 1, 0); bool expected = true; bool actual = instance.Connect(hostName, portNumber); @@ -61,9 +65,10 @@ BOOST_AUTO_TEST_CASE(Connect) BOOST_AUTO_TEST_CASE(Send) { + char *hostName = REMOTE_IP_ADDRESS; + int portNumber = REMOTE_PORT; + SocketBase instance(2, 1, 0); - char *hostName = A_ROOT_SERVER_NET; - int portNumber = DNS_PORT; char *message = "00000001"; @@ -75,9 +80,10 @@ BOOST_AUTO_TEST_CASE(Send) BOOST_AUTO_TEST_CASE(Receive) { + char *hostName = REMOTE_IP_ADDRESS; + int portNumber = REMOTE_PORT; + SocketBase instance(2, 1, 0); - char *hostName = A_ROOT_SERVER_NET; - int portNumber = DNS_PORT; char *message = "00000001"; instance.Send(message); @@ -91,9 +97,10 @@ BOOST_AUTO_TEST_CASE(Receive) BOOST_AUTO_TEST_CASE(Id) { + char *hostName = REMOTE_IP_ADDRESS; + int portNumber = REMOTE_PORT; + SocketBase instance(2, 1, 0); - char *hostName = A_ROOT_SERVER_NET; - int portNumber = DNS_PORT; bool expected = 1; bool actual = instance.Id(); diff --git a/tests/Sockets/src/Socket_Spec.cpp b/tests/Sockets/src/Socket_Spec.cpp index 5368517..aabe121 100644 --- a/tests/Sockets/src/Socket_Spec.cpp +++ b/tests/Sockets/src/Socket_Spec.cpp @@ -12,6 +12,10 @@ #include "../../../src/Sockets/Socket.h" #include "../../TestTool.h" +// define test environment +char *REMOTE_IP_ADDRESS = A_ROOT_SERVER_NET; +int REMOTE_PORT = strtol(DNS_PORT, NULL, 10); + bool Constractor_AddressFamiliySpec() { Socket instance(AddressFamiliy::InterNetwork, SocketType::Stream, ProtocolType::Ip); @@ -47,8 +51,8 @@ bool Constractor_ProtocolTypeSpec() bool CreateSpec() { - char *hostName = (char *)A_ROOT_SERVER_NET; - int portNumber = DNS_PORT; + char *hostName = REMOTE_IP_ADDRESS; + int portNumber = REMOTE_PORT; Socket instance(AddressFamiliy::InterNetwork, SocketType::Stream, ProtocolType::Ip); @@ -61,8 +65,8 @@ bool CreateSpec() bool ConnectSpec() { - char *hostName = (char *)A_ROOT_SERVER_NET; - int portNumber = DNS_PORT; + char *hostName = REMOTE_IP_ADDRESS; + int portNumber = REMOTE_PORT; IpAddress ipAddress(hostName); IpEndPoint ipEndPoint(ipAddress, portNumber); @@ -78,8 +82,8 @@ bool ConnectSpec() bool SendSpec() { - char *hostName = (char *); - int portNumber = DNS_PORT; + char *hostName = REMOTE_IP_ADDRESS; + int portNumber = REMOTE_PORT; IpAddress ipAddress(hostName); IpEndPoint ipEndPoint(ipAddress, portNumber); @@ -99,8 +103,8 @@ bool SendSpec() bool ReceiveSpec() { - char *hostName = (char *)A_ROOT_SERVER_NET; - int portNumber = DNS_PORT; + char *hostName = REMOTE_IP_ADDRESS; + int portNumber = REMOTE_PORT; IpAddress ipAddress(hostName); IpEndPoint ipEndPoint(ipAddress, portNumber); @@ -122,8 +126,8 @@ bool ReceiveSpec() bool IdSpec() { - char *hostName = (char *)A_ROOT_SERVER_NET; - int portNumber = DNS_PORT; + char *hostName = REMOTE_IP_ADDRESS; + int portNumber = REMOTE_PORT; IpAddress ipAddress(hostName); IpEndPoint ipEndPoint(ipAddress, portNumber); diff --git a/tests/Sockets/src/Socket_Test.cpp b/tests/Sockets/src/Socket_Test.cpp index 62f1115..b1a2bf4 100644 --- a/tests/Sockets/src/Socket_Test.cpp +++ b/tests/Sockets/src/Socket_Test.cpp @@ -14,6 +14,10 @@ #define BOOST_TEST_MODULE SocketTest #include +// define test environment +char *REMOTE_IP_ADDRESS = A_ROOT_SERVER_NET; +int REMOTE_PORT = strtol(DNS_PORT, NULL, 10); + BOOST_AUTO_TEST_SUITE(Socket_Suite) BOOST_AUTO_TEST_CASE(Constractor_AddressFamiliy) { @@ -44,8 +48,11 @@ BOOST_AUTO_TEST_CASE(Constractor_ProtocolType) BOOST_AUTO_TEST_CASE(Connect) { + char *hostName = REMOTE_IP_ADDRESS; + int portNumber = REMOTE_PORT; + Socket instance(AddressFamiliy::InterNetwork, SocketType::Stream, ProtocolType::Ip); - IpEndPoint ipEndPoint(A_ROOT_SERVER_NET, DNS_PORT); + IpEndPoint ipEndPoint(hostName, portNumber); bool expected = true; bool actual = instance.Connect(ipEndPoint); @@ -54,8 +61,11 @@ BOOST_AUTO_TEST_CASE(Connect) BOOST_AUTO_TEST_CASE(Send) { + char *hostName = REMOTE_IP_ADDRESS; + int portNumber = REMOTE_PORT; + Socket instance(AddressFamiliy::InterNetwork, SocketType::Stream, ProtocolType::Ip); - IpEndPoint ipEndPoint(A_ROOT_SERVER_NET, DNS_PORT); + IpEndPoint ipEndPoint(hostName, portNumber); char *message = "00000001"; bool expected = 1; bool actual = instance.Send(message); @@ -65,8 +75,11 @@ BOOST_AUTO_TEST_CASE(Send) BOOST_AUTO_TEST_CASE(Receive) { + char *hostName = REMOTE_IP_ADDRESS; + int portNumber = REMOTE_PORT; + Socket instance(AddressFamiliy::InterNetwork, SocketType::Stream, ProtocolType::Ip); - IpEndPoint ipEndPoint(A_ROOT_SERVER_NET, DNS_PORT); + IpEndPoint ipEndPoint(hostName, portNumber); char *message = "00000001"; instance.Send(message); bool expected = 1; @@ -78,8 +91,11 @@ BOOST_AUTO_TEST_CASE(Receive) BOOST_AUTO_TEST_CASE(Id) { + char *hostName = REMOTE_IP_ADDRESS; + int portNumber = REMOTE_PORT; + Socket instance(AddressFamiliy::InterNetwork, SocketType::Stream, ProtocolType::Ip); - IpEndPoint ipEndPoint(A_ROOT_SERVER_NET, DNS_PORT); + IpEndPoint ipEndPoint(hostName, portNumber); bool expected = 1; bool actual = instance.Id();