From df96399e469cde20adfd618e4a4dd6a12a941a31 Mon Sep 17 00:00:00 2001
From: Pavel Kirilin <win10@list.ru>
Date: Tue, 4 Jan 2022 10:41:14 +0400
Subject: [PATCH] Added docker build CI\CD.

Signed-off-by: Pavel Kirilin <win10@list.ru>
---
 .github/workflows/docker.yml | 35 +++++++++++++++++++++++++++++++++++
 .github/workflows/lint.yml   | 17 +++++++++++++++++
 Cargo.toml                   |  4 ++++
 3 files changed, 56 insertions(+)
 create mode 100644 .github/workflows/docker.yml
 create mode 100644 .github/workflows/lint.yml

diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml
new file mode 100644
index 0000000..b044fdf
--- /dev/null
+++ b/.github/workflows/docker.yml
@@ -0,0 +1,35 @@
+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
new file mode 100644
index 0000000..584cd7b
--- /dev/null
+++ b/.github/workflows/lint.yml
@@ -0,0 +1,17 @@
+on: push
+name: Lint check
+jobs:
+  clippy_check:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v1
+      - run: rustup component add clippy
+      - uses: actions-rs/clippy-check@v1
+        with:
+          token: ${{ secrets.GITHUB_TOKEN }}
+          args: --all-features -p rustus -- -W clippy::all -W clippy::pedantic -D warnings
+  fmt_check:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v1
+      - run: cargo fmt -- --check
\ No newline at end of file
diff --git a/Cargo.toml b/Cargo.toml
index 9fd4336..f3e6372 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -4,6 +4,10 @@ version = "0.1.0"
 edition = "2021"
 description = "TUS protocol implementation written in Rust."
 
+[profile.release]
+lto = true
+opt-level = "z"  # Optimize for size.
+
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 [[bin]]
 name = "rustus"
-- 
GitLab