Skip to content

Commit

Permalink
Merge pull request #1 from azmisahin/stage
Browse files Browse the repository at this point in the history
Stage
  • Loading branch information
azmisahin authored May 16, 2022
2 parents e884357 + c858d0a commit 5d80b0c
Show file tree
Hide file tree
Showing 13 changed files with 290 additions and 66 deletions.
32 changes: 31 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
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}
19 changes: 16 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -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"
}
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
14 changes: 14 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -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"
58 changes: 58 additions & 0 deletions Dockerfile.linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# base operation system image
FROM ubuntu:latest AS production

# Metadata indicating an image maintainer.
LABEL maintainer="Azmi ŞAHİN <[email protected]>"

# 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}\""]
58 changes: 58 additions & 0 deletions Dockerfile.windows
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"

# 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%"
39 changes: 39 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
24 changes: 0 additions & 24 deletions install.sh

This file was deleted.

6 changes: 4 additions & 2 deletions src/Sockets/IpAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
#ifndef IPADDRESS_H
#define IPADDRESS_H

#define A_ROOT_SERVER_NET "198.41.0.4"
#define DNS_PORT 53
#include <cstdlib>
// 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
Expand Down
32 changes: 19 additions & 13 deletions tests/Sockets/src/SocketBase_Spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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";

Expand All @@ -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";

Expand All @@ -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";

Expand All @@ -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();
Expand Down
Loading

0 comments on commit 5d80b0c

Please sign in to comment.