From 5f4b716ff24abe340ec2ca16afd60a19f08d3e81 Mon Sep 17 00:00:00 2001
From: Hugo Trentesaux <hugo@trentesaux.fr>
Date: Tue, 5 Mar 2024 21:59:34 +0100
Subject: [PATCH] wip dockerfile

TODO make duniter-polkadot-sdk repo lighter to avoid long download time in docker build
---
 .dockerignore    |  1 +
 Dockerfile       | 37 +++++++++++++++++++++++++++++++++++++
 docker/README.md | 19 +++++++++++++++++++
 docker/build.sh  | 15 +++++++++++++++
 4 files changed, 72 insertions(+)
 create mode 100644 .dockerignore
 create mode 100644 Dockerfile
 create mode 100644 docker/README.md
 create mode 100755 docker/build.sh

diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..2f7896d
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1 @@
+target/
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..2a3bbb7
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,37 @@
+# This Dockerfile was generated by chatGPT and then modified
+
+# Use the official Rust image as the base image for building
+FROM rust:latest as build
+# # Use musl Rust image
+# FROM clux/muslrust:1.75.0-stable as build
+
+# Create a new directory for our application code inside the container
+WORKDIR /usr/src/gcli
+
+# Copy the Cargo.toml and Cargo.lock files to leverage Docker's caching mechanism
+COPY Cargo.toml Cargo.lock ./
+
+# Build the dependencies of the application separately
+RUN mkdir src \
+    && echo "fn main() {}" > src/main.rs \
+    && cargo build --release \
+    && rm -r src
+
+# Copy the rest of the source code
+COPY ./res ./res
+COPY ./src ./src
+
+# Build the application
+RUN cargo build --release
+
+# # Start realease stage
+# FROM alpine:latest as release
+
+# # Set the working directory to the location of the built application
+# WORKDIR /usr/bin/gcli
+
+# # Copy the built application from the previous stage
+# COPY --from=build /usr/src/gcli/target/release/gcli .
+
+# # Specify the entrypoint for the container
+# ENTRYPOINT ["./gcli"]
\ No newline at end of file
diff --git a/docker/README.md b/docker/README.md
new file mode 100644
index 0000000..529ec70
--- /dev/null
+++ b/docker/README.md
@@ -0,0 +1,19 @@
+# Docker
+
+Docker image for gcli is useful for people with docker-based infrastructure or old system with old glibc or libssl.
+
+## Build
+
+```sh
+./docker/build.sh
+```
+
+## Use
+
+An alias can be useful:
+
+```sh
+alias gcli="docker run gcli"
+```
+
+Keep in mind that gcli stores its config and vault, you can mount volumes on these.
\ No newline at end of file
diff --git a/docker/build.sh b/docker/build.sh
new file mode 100755
index 0000000..a327c02
--- /dev/null
+++ b/docker/build.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+# Also generated by chatGPT
+
+# Name of your Docker image
+IMAGE_NAME="gcli"
+
+# Version of your Docker image
+IMAGE_VERSION="latest"
+
+# Build and tag the Docker image using Docker Buildx
+docker buildx build -t "$IMAGE_NAME:$IMAGE_VERSION" .
+
+# Optionally, you can push the image to a Docker registry
+# docker push "$IMAGE_NAME:$IMAGE_VERSION"
-- 
GitLab