From c2910aaef34cc70d4217564dba7661ef42010c8c Mon Sep 17 00:00:00 2001
From: Jack Wills <32690432+mrjackwills@users.noreply.github.com>
Date: Mon, 5 Sep 2022 22:05:24 +0000
Subject: [PATCH] feat: self containerisation
Build oxker images, for x86, arm64v8, and armv6, and publish to Docker Hub
---
Dockerfile | 47 ---------------
README.md | 8 ++-
containerised/DOCKERHUB_README.md | 26 +++++++++
containerised/Dockerfile | 58 +++++++++++++++++++
containerised/create_docker_images.sh | 10 ++++
containerised/platform.sh | 19 ++++++
.../start_oxker.sh | 0
7 files changed, 120 insertions(+), 48 deletions(-)
delete mode 100644 Dockerfile
create mode 100644 containerised/DOCKERHUB_README.md
create mode 100644 containerised/Dockerfile
create mode 100644 containerised/create_docker_images.sh
create mode 100644 containerised/platform.sh
rename start_oxker.sh => containerised/start_oxker.sh (100%)
diff --git a/Dockerfile b/Dockerfile
deleted file mode 100644
index 8b8e972..0000000
--- a/Dockerfile
+++ /dev/null
@@ -1,47 +0,0 @@
-#############
-## Builder ##
-#############
-
-FROM rust:1.63.0-slim as builder
-
-WORKDIR /usr/src
-
-# Create blank project
-RUN USER=root cargo new oxker
-
-# We want dependencies cached, so copy those first.
-COPY Cargo.toml Cargo.lock /usr/src/oxker/
-
-# Set the working directory
-WORKDIR /usr/src/oxker
-
-## Install target platform (Cross-Compilation) --> Needed for Alpine
-RUN rustup target add x86_64-unknown-linux-musl
-
-# This is a dummy build to get the dependencies cached.
-RUN cargo build --target x86_64-unknown-linux-musl --release
-
-# Now copy in the rest of the sources
-COPY src /usr/src/oxker/src/
-
-## Touch main.rs to prevent cached release build
-RUN touch /usr/src/oxker/src/main.rs
-
-# This is the actual application build.
-RUN cargo build --target x86_64-unknown-linux-musl --release
-
-#############
-## Runtime ##
-#############
-
-FROM alpine:latest AS runtime
-
-# Copy application binary from builder image
-COPY --from=builder /usr/src/oxker/target/x86_64-unknown-linux-musl/release/oxker /usr/local/bin
-COPY start_oxker.sh ./
-RUN chmod +x /start_oxker.sh
-
-# Run the application
-ENTRYPOINT [ "./start_oxker.sh"]
-
-# docker run --rm -it --volume /var/run/docker.sock:/var/run/docker.sock:ro oxker
\ No newline at end of file
diff --git a/README.md b/README.md
index db64461..284f335 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
-
+
@@ -20,6 +20,12 @@
+## Run via Docker
+
+Now published on Docker Hub, with images built for `linux/amd64`, `linux/arm64v8`, and `linux/armv6`
+
+`docker run --rm -it --volume /var/run/docker.sock:/var/run/docker.sock:ro mrjackwills/oxker:latest`
+
## Download & install
diff --git a/containerised/DOCKERHUB_README.md b/containerised/DOCKERHUB_README.md
new file mode 100644
index 0000000..d8ef143
--- /dev/null
+++ b/containerised/DOCKERHUB_README.md
@@ -0,0 +1,26 @@
+
+
+
+
+
+
oxker
+
+ A simple tui to view & control docker containers
+
+
+
+
+
+
+
+
+
+## Run
+
+Images built for `linux/amd64`, `linux/arm64v8`, and `linux/armv6`
+
+`docker run --rm -it --volume /var/run/docker.sock:/var/run/docker.sock:ro mrjackwills/oxker:latest`
+
+## Help
+
+visit the Github repo
\ No newline at end of file
diff --git a/containerised/Dockerfile b/containerised/Dockerfile
new file mode 100644
index 0000000..d5e77ca
--- /dev/null
+++ b/containerised/Dockerfile
@@ -0,0 +1,58 @@
+#############
+## Builder ##
+#############
+
+FROM --platform=linux/amd64 rust:slim as builder
+
+ARG TARGETARCH
+
+ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER="aarch64-linux-gnu-gcc"
+ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS="-C target-feature=+crt-static -C link-arg=-lgcc"
+ENV CARGO_TARGET_ARM_UNKNOWN_LINUX_MUSLEABIHF_LINKER="arm-linux-gnueabihf-ld"
+
+COPY ./containerised/platform.sh .
+
+RUN chmod +x ./platform.sh && ./platform.sh
+
+RUN apt-get update && apt-get install $(cat /.compiler) -y
+
+WORKDIR /usr/src
+
+# Create blank project
+RUN cargo new oxker
+
+# We want dependencies cached, so copy those first
+COPY Cargo.toml Cargo.lock /usr/src/oxker/
+
+# Set the working directory
+WORKDIR /usr/src/oxker
+
+# Install target platform (Cross-Compilation)
+RUN rustup target add $(cat /.platform)
+
+# This is a dummy build to get the dependencies cached
+RUN cargo build --target $(cat /.platform) --release
+
+# Now copy in the rest of the sources
+COPY src /usr/src/oxker/src/
+
+## Touch main.rs to prevent cached release build
+RUN touch /usr/src/oxker/src/main.rs
+
+# This is the actual application build
+RUN cargo build --release --target $(cat /.platform)
+
+RUN cp /usr/src/oxker/target/$(cat /.platform)/release/oxker /
+
+#############
+## Runtime ##
+#############
+
+FROM alpine:latest AS runtime
+
+# Copy application binary from builder image
+COPY --from=builder /oxker /usr/local/bin
+COPY ./containerised/start_oxker.sh ./
+
+# Run the application
+ENTRYPOINT [ "./start_oxker.sh"]
\ No newline at end of file
diff --git a/containerised/create_docker_images.sh b/containerised/create_docker_images.sh
new file mode 100644
index 0000000..9a44e05
--- /dev/null
+++ b/containerised/create_docker_images.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+docker login
+
+docker buildx prune
+
+docker buildx build --platform linux/arm/v6,linux/arm64,linux/amd64 -t mrjackwills/oxker --push -f containerised/Dockerfile .
+
+# Github as well?
+# docker buildx build --platform linux/arm/v6,linux/arm64,linux/amd64 -t ghcr.io/mrjackwills/oxker --push -f containerised/Dockerfile .
\ No newline at end of file
diff --git a/containerised/platform.sh b/containerised/platform.sh
new file mode 100644
index 0000000..43da224
--- /dev/null
+++ b/containerised/platform.sh
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+# Used in Docker build to set platform dependent variables
+
+case $TARGETARCH in
+
+ "amd64")
+ echo "x86_64-unknown-linux-musl" > /.platform
+ echo "" > /.compiler
+ ;;
+ "arm64")
+ echo "aarch64-unknown-linux-musl" > /.platform
+ echo "gcc-aarch64-linux-gnu" > /.compiler
+ ;;
+ "arm")
+ echo "arm-unknown-linux-musleabihf" > /.platform
+ echo "gcc-arm-linux-gnueabihf" > /.compiler
+ ;;
+esac
\ No newline at end of file
diff --git a/start_oxker.sh b/containerised/start_oxker.sh
similarity index 100%
rename from start_oxker.sh
rename to containerised/start_oxker.sh