diff --git a/.gitignore b/.gitignore index a8a8eb8..3b6968c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .vscode build -ccash_config.hpp \ No newline at end of file +ccash_config.hpp +deployment/.yamllint \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 80a789e..5243745 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,21 @@ -FROM alpine:3.11 +FROM alpine:latest WORKDIR / -RUN apk update && apk add git cmake g++ make protobuf jsoncpp-dev openssl libressl-dev zlib-dev util-linux-dev libtool autoconf automake python3 +RUN apk update && apk add bash git cmake g++ make protobuf jsoncpp-dev openssl libressl-dev zlib-dev util-linux-dev libtool autoconf automake python3 RUN git clone --recurse-submodules https://github.com/EntireTwix/CCash.git WORKDIR /CCash/third_party/base64/ RUN AVX2_CFLAGS=-mavx2 SSSE3_CFLAGS=-mssse3 SSE41_CFLAGS=-msse4.1 SSE42_CFLAGS=-msse4.2 AVX_CFLAGS=-mavx make lib/libbase64.o RUN mkdir /CCash/build WORKDIR /CCash/build -RUN cmake -DDROGON_CONFIG_LOC=/CCash/config/config.json -DUSER_SAVE_LOC=/CCash/config/users.dat .. +RUN cmake -DDROGON_CONFIG_LOC="/CCash/config/config.json" -DUSER_SAVE_LOC="/CCash/config/users.dat" .. RUN make -j$(nproc) ARG ADMIN_A=admin ARG SAVE_FREQ=2 - -CMD ["sh", "-c", "/CCash/config/ssl.sh && /CCash/build/bank ${ADMIN_A} ${SAVE_FREQ}"] \ No newline at end of file +WORKDIR / +RUN sed -i 's/\r$//' /CCash/config/ssl.sh && \ + chmod +x /CCash/config/ssl.sh +RUN /CCash/build/bank +CMD /CCash/config/ssl.sh && /CCash/build/bank ${ADMIN_A} ${SAVE_FREQ} \ No newline at end of file diff --git a/deployment/inventory b/deployment/inventory new file mode 100644 index 0000000..f8d136f --- /dev/null +++ b/deployment/inventory @@ -0,0 +1,2 @@ +[all] +10.10.0.145 ansible_ssh_user=root ansible_ssh_common_args='-o StrictHostKeyChecking=no' \ No newline at end of file diff --git a/deployment/main.yml b/deployment/main.yml new file mode 100644 index 0000000..34dcaae --- /dev/null +++ b/deployment/main.yml @@ -0,0 +1,96 @@ +--- +- hosts: all + vars: + become: true + pre_tasks: + - name: load variables + ansible.builtin.include_vars: '{{ item }}' + with_first_found: + - "default.yml" + + + tasks: + - name: refresh packages update + yum: + name: "*" + update_cache: true + state: latest + + - name: Add repository + yum: + name: epel-release + state: latest + when: ansible_os_family == "RedHat" + + - name: install dependencies + yum: + name: [git, gcc, gcc-c++, libuuid-devel, openssl-devel, zlib-devel, jsoncpp-devel, cmake] + state: present + when: ansible_os_family == "RedHat" + + - name: clone CCash repository + git: + repo: https://github.com/EntireTwix/CCash.git + dest: '{{BUILD_DIR}}/CCash' + recursive: true + update: false + + - name: Make lib base64 + community.general.make: + chdir: '{{BUILD_DIR}}/CCash/third_party/base64' + params: + AVX2_CFLAGS: -mavx2 + SSSE3_CFLAGS: -mssse3 + SSE41_CFLAGS: -msse4.1 + SSE42_CFLAGS: -msse4.2 + AVX_CFLAGS: -mavx + + - name: create build dir + file: + path: '{{BUILD_DIR}}/CCash/build' + state: directory + + - name: Cmake CCash + ansible.builtin.command: + chdir: '{{BUILD_DIR}}/CCash/build' + cmd: | + cmake -DDROGON_CONFIG_LOC="{{ BUILD_DIR }}/CCash/config/config.json" -DUSER_SAVE_LOC="{{ BUILD_DIR }}/CCash/config/users.dat" .. + + - name: make CCash + community.general.make: + chdir: '{{BUILD_DIR}}/CCash/build' + params: + NUM_THREADS: '-j{{ ansible_processor_vcpus }}' + + + - name: create users file + ansible.builtin.command: + chdir: '{{BUILD_DIR}}/CCash/build/' + cmd: ./bank + creates: '{{ BUILD_DIR }}/CCash/config/users.dat' + - name: chmod +x ssl.sh + ansible.builtin.file: + mode: u+x + path: '{{BUILD_DIR}}/CCash/config/ssl.sh' + - name: generate default ssl + ansible.builtin.command: + chdir: '{{BUILD_DIR}}/CCash/config/' + cmd: './ssl.sh' + + - name: create service file + ansible.builtin.copy: + content: | + [Unit] + Description=CCash API Server + After=network.target remote-fs.target nss-lookup.target + + [Service] + Type=simple + ExecStart={{BUILD_DIR}}/CCash/build/bank {{ADMIN_A}} {{SAVE_FREQ}} + ExecStop=/bin/kill -WINCH ${MAINPID} + KillSignal=SIGCONT + PrivateTmp=true + + [Install] + WantedBy=multi-user.target + dest: /etc/systemd/system/ccash.service \ No newline at end of file diff --git a/deployment/vars/default.yml b/deployment/vars/default.yml new file mode 100644 index 0000000..95a253b --- /dev/null +++ b/deployment/vars/default.yml @@ -0,0 +1,4 @@ +--- +BUILD_DIR: '/root' +ADMIN_A: "admin" +SAVE_FREQ: "2" \ No newline at end of file