From 70224f337ae1edf7e4131422edfa7e3a3f3275cd Mon Sep 17 00:00:00 2001
From: Pavel Kirilin <win10@list.ru>
Date: Mon, 20 Feb 2023 01:48:25 +0400
Subject: [PATCH] Added Dockerfile and tests.

Signed-off-by: Pavel Kirilin <win10@list.ru>
---
 .gitlab-ci.yml | 26 +++++++++++++++++++++++---
 Dockerfile     | 24 ++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 3 deletions(-)
 create mode 100644 Dockerfile

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index cf9cc37..5ffc2ce 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -8,10 +8,30 @@
 stages:
   - test
 
-sast:
+.test-template:
   tags:
     - kube
+  image: rust:1.67.1-buster
   stage: test
+  interruptible: true
+  before_script:
+    - apt update
+    - apt install -y python3 python3-pip
+    - pip3 install pre-commit
 
-include:
-  - template: Security/SAST.gitlab-ci.yml
+app-tests:
+  extends: .test-template
+  script:
+    - cargo test
+
+clippy:
+  extends: .test-template
+  script:
+    - rustup component add clippy
+    - pre-commit run clippy -av
+
+fmt:
+  extends: .test-template
+  script:
+    - rustup component add rustfmt
+    - pre-commit run fmt -av
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..08ebc90
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,24 @@
+FROM rust:1.67.1-alpine3.17 as builder
+
+WORKDIR /app
+COPY Cargo.toml Cargo.lock ./
+COPY src ./src
+RUN cargo build --release --all-features
+
+FROM debian:bullseye-20230109-slim as base
+
+RUN apt-get update \
+    && apt-get install -y openssl ca-certificates \
+    && rm -rf /var/lib/apt/lists/*
+
+COPY static ./static
+
+COPY --from=builder /app/target/release/s3bot /usr/local/bin/
+
+ENTRYPOINT ["/usr/local/bin/s3bot"]
+
+FROM base as rootless
+
+RUN useradd --create-home  -u 1000 --user-group s3bot
+WORKDIR /home/s3bot
+USER s3bot
-- 
GitLab