From c0b7c099c79bdedf059a8936bb3270eaab7360e5 Mon Sep 17 00:00:00 2001
From: Pavel Kirilin <win10@list.ru>
Date: Wed, 5 Jan 2022 13:21:21 +0400
Subject: [PATCH] Updated README and CI\CD.

Signed-off-by: Pavel Kirilin <win10@list.ru>
---
 .github/dependabot.yml        |   9 +++
 .github/workflows/docker.yml  |  35 ----------
 .github/workflows/lint.yml    |   6 +-
 .github/workflows/release.yml | 127 ++++++++++++++++++++++++++++++++++
 README.md                     |  53 ++++++++++++--
 5 files changed, 187 insertions(+), 43 deletions(-)
 create mode 100644 .github/dependabot.yml
 delete mode 100644 .github/workflows/docker.yml
 create mode 100644 .github/workflows/release.yml

diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 0000000..cc7a72a
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,9 @@
+version: 2
+updates:
+  - package-ecosystem: cargo
+    # Look for `Cargo.toml` and `Cargo.lock` in the root directory
+    directory: "/"
+    # Check for updates every Monday
+    schedule:
+      interval: weekly
+    open-pull-requests-limit: 2
\ No newline at end of file
diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml
deleted file mode 100644
index b044fdf..0000000
--- a/.github/workflows/docker.yml
+++ /dev/null
@@ -1,35 +0,0 @@
-on:
-  workflow_run:
-    workflows:
-      - "Lint check"
-    branches:
-      - master
-    types:
-      - completed
-
-name: Docker build
-jobs:
-  docker_build:
-    if: ${{ github.event.workflow_run.conclusion == 'success' }}
-    runs-on: ubuntu-latest
-    steps:
-      - name: Checkout
-        uses: actions/checkout@v2
-      - name: Set up QEMU
-        uses: docker/setup-qemu-action@v1
-      - name: Set up Docker Buildx
-        uses: docker/setup-buildx-action@v1
-      - name: Login to DockerHub
-        uses: docker/login-action@v1
-        with:
-          username: ${{ secrets.DOCKERHUB_USERNAME }}
-          password: ${{ secrets.DOCKERHUB_TOKEN }}
-      - name: Export version
-        run: echo "APP_VERSION=$(head -n 5 Cargo.toml | grep version | cut -d '"' -f2)" >> $GITHUB_ENV
-      - name: Build and push
-        uses: docker/build-push-action@v2
-        with:
-          context: .
-          push: true
-          file: deploy/Dockerfile
-          tags: s3rius/rustus:latest,s3rius/rustus:${{env.APP_VERSION}}
\ No newline at end of file
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index 584cd7b..e4bf7c0 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -1,4 +1,8 @@
-on: push
+on:
+  push:
+    tags-ignore:
+      - '**'
+
 name: Lint check
 jobs:
   clippy_check:
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
new file mode 100644
index 0000000..6156872
--- /dev/null
+++ b/.github/workflows/release.yml
@@ -0,0 +1,127 @@
+name: Release
+
+on:
+  push:
+    tags:
+      - '*'
+
+jobs:
+  publish:
+    name: Publishing for ${{ matrix.job.os }}
+    runs-on: ${{ matrix.job.os }}
+    strategy:
+      matrix:
+        rust: [stable]
+        job:
+          - os: macos-latest
+            os-name: macos
+            target: x86_64-apple-darwin
+            architecture: x86_64
+            binary-postfix: ""
+            use-cross: false
+          - os: ubuntu-latest
+            os-name: linux
+            target: x86_64-unknown-linux-gnu
+            architecture: x86_64
+            binary-postfix: ""
+            use-cross: false
+          - os: windows-latest
+            os-name: windows
+            target: x86_64-pc-windows-msvc
+            architecture: x86_64
+            binary-postfix: ".exe"
+            use-cross: false
+#          - os: ubuntu-latest
+#            os-name: linux
+#            target: aarch64-unknown-linux-gnu
+#            architecture: arm64
+#            binary-postfix: ""
+#            use-cross: true
+#          - os: ubuntu-latest
+#            os-name: linux
+#            target: i686-unknown-linux-gnu
+#            architecture: i686
+#            binary-postfix: ""
+#            use-cross: true
+
+    steps:
+      - name: Checkout repository
+        uses: actions/checkout@v2
+      - name: Install Rust toolchain
+        uses: actions-rs/toolchain@v1
+        with:
+          toolchain: ${{ matrix.rust }}
+          profile: minimal
+          override: true
+      - uses: Swatinem/rust-cache@v1
+      - name: Cargo build
+        uses: actions-rs/cargo@v1
+        with:
+          command: build
+          use-cross: ${{ matrix.job.use-cross }}
+          toolchain: ${{ matrix.rust }}
+          args: --release --features=all --target ${{ matrix.job.target }}
+
+      - name: install strip command
+        shell: bash
+        run: |
+          if [[ ${{ matrix.job.target }} == aarch64-unknown-linux-gnu ]]; then
+              sudo apt update
+              sudo apt-get install -y binutils-aarch64-linux-gnu
+          fi
+      - name: Packaging final binary
+        shell: bash
+        run: |
+          cd target/${{ matrix.job.target }}/release
+
+          ####### reduce binary size by removing debug symbols #######
+          BINARY_NAME=rustus${{ matrix.job.binary-postfix }}
+          if [[ ${{ matrix.job.target }} == aarch64-unknown-linux-gnu ]]; then
+            GCC_PREFIX="aarch64-linux-gnu-"
+          else
+            GCC_PREFIX=""
+          fi
+          "$GCC_PREFIX"strip $BINARY_NAME
+
+          ########## create tar.gz ##########
+          RELEASE_NAME=rustus-${GITHUB_REF/refs\/tags\//}-${{ matrix.job.os-name }}-${{ matrix.job.architecture }}
+          tar czvf $RELEASE_NAME.tar.gz $BINARY_NAME
+
+          ########## create sha256 ##########
+          if [[ ${{ runner.os }} == 'Windows' ]]; then
+            certutil -hashfile $RELEASE_NAME.tar.gz sha256 | grep -E [A-Fa-f0-9]{64} > $RELEASE_NAME.sha256
+          else
+            shasum -a 256 $RELEASE_NAME.tar.gz > $RELEASE_NAME.sha256
+          fi
+      - name: Releasing assets
+        uses: softprops/action-gh-release@v1
+        with:
+          files: |
+            target/${{ matrix.job.target }}/release/rustus-*.tar.gz
+            target/${{ matrix.job.target }}/release/rustus-*.sha256
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+
+  docker_build:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v2
+      - name: Set up QEMU
+        uses: docker/setup-qemu-action@v1
+      - name: Set up Docker Buildx
+        uses: docker/setup-buildx-action@v1
+      - name: Login to DockerHub
+        uses: docker/login-action@v1
+        with:
+          username: ${{ secrets.DOCKERHUB_USERNAME }}
+          password: ${{ secrets.DOCKERHUB_TOKEN }}
+      - name: Export version
+        run: echo "APP_VERSION=$(head -n 5 Cargo.toml | grep version | cut -d '"' -f2)" >> $GITHUB_ENV
+      - name: Build and push
+        uses: docker/build-push-action@v2
+        with:
+          context: .
+          push: true
+          file: deploy/Dockerfile
+          tags: s3rius/rustus:latest,s3rius/rustus:${{env.APP_VERSION}}
\ No newline at end of file
diff --git a/README.md b/README.md
index 45012b8..3e91338 100644
--- a/README.md
+++ b/README.md
@@ -32,10 +32,10 @@ from source using `cargo`.
 cargo install --path .
 ```
 
-Or you can build a docker image.
+Or you can use a docker image.
 
 ```bash
-docker build --tag="rustus:latest" --cache-from=s3rius/tuser:latest -f deploy/Dockerfile .
+docker run --rm -it -p 1081:1081 s3rius/rustus:latest
 ```
 
 Docker image and binaries will be available soon.
@@ -47,13 +47,52 @@ In order to modify original file rustus searches for information about
 the file in information storage.
 
 However, automatic migration between different information
-storages is not supported.
+storages is not supported yet.
 
+## Info storages
 
-## Configuration
+The info storage is a database or directory. The main goal is to keep track
+of uploads. Rustus stores information about download in json format inside
+database.
+
+File storage is a default one. You can customize the directory of an .info files
+by providing `--info-dir` parameter.
+
+```bash
+rustus --info-dir "./info_dir"
+```
+
+If you want to choose different storage you have to specify its type and connection string.
+
+```bash
+# Redis info storage
+rustus --info-storage redis-info-storage --info-db-dsn "redis://localhost"
+# PostgreSQL info storage
+rustus --info-storage db-info-storage --info-db-dsn "postgres://rustus:rustus@192.168.1.89:5440/rustus"
+# SQLite3 info storage
+rustus --info-storage db-info-storage --info-db-dsn "sqlite:////test.sqlite3"
+# MySQL
+rustus --info-storage db-info-storage --info-db-dsn "mysql://rustus:rustus@192.168.1.89:3306/rustus"
+```
+
+## Hooks
+
+Rustus supports several event hooks, such as:
+* File hooks;
+* HTTP hooks;
+* AMQP hooks.
+
+You can combine them, but you have to be careful, since
+AMQP hooks won't block uploading.
+
+If you want to check the "Authorization" header value or validate some information,
+you have to use webhooks or File hooks.
+
+Hooks have priorities: file hooks are the most important, then goes webhooks and AMQP hooks have the least priority.
+If pre-create hook failed, the upload would not start.
+Of course, since AMQP is a protocol that doesn't allow you to track responses.
+We can't validate anything to stop uploading.
 
-You can configure rustus via command line or environment variables.
-All options are listed in `rustus --help`.
 
 ### Roadmap
 
@@ -71,7 +110,7 @@ All options are listed in `rustus --help`.
 * [x] Notification interface;
 * [x] Notifications via http hooks;
 * [x] Notifications via RabbitMQ;
-* [ ] S3 as data storage store support;
 * [ ] Executable files notifications;
+* [ ] S3 as data storage store support;
 * [ ] Rustus helm chart;
 * [ ] Cloud native rustus operator.
-- 
GitLab