From f77b758daa98b61cac12f15660f5d99c617426a6 Mon Sep 17 00:00:00 2001 From: Fabian Schmidt Date: Mon, 16 Sep 2024 16:17:04 +0200 Subject: [PATCH] First draft of a template for lua scripts --- .gitea/workflows/template.yaml | 19 --------- Cargo.lock | 7 ---- Cargo.toml | 11 ----- docker-compose.yml | 8 +--- docker/alpine.Dockerfile | 54 ++---------------------- docker/distroless.Dockerfile | 46 -------------------- docker/scratch.Dockerfile | 76 ---------------------------------- src/main.lua | 1 + src/main.rs | 3 -- 9 files changed, 6 insertions(+), 219 deletions(-) delete mode 100644 .gitea/workflows/template.yaml delete mode 100644 Cargo.lock delete mode 100644 Cargo.toml delete mode 100644 docker/distroless.Dockerfile delete mode 100755 docker/scratch.Dockerfile create mode 100644 src/main.lua delete mode 100644 src/main.rs diff --git a/.gitea/workflows/template.yaml b/.gitea/workflows/template.yaml deleted file mode 100644 index 14a5815..0000000 --- a/.gitea/workflows/template.yaml +++ /dev/null @@ -1,19 +0,0 @@ -name: Gitea Actions Template -run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀 -on: [push] - -jobs: - Explore-Gitea-Actions: - runs-on: ubuntu-latest - steps: - - run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event." - - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!" - - run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}." - - name: Check out repository code - uses: actions/checkout@v4 - - run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner." - - run: echo "🖥️ The workflow is now ready to test your code on the runner." - - name: List files in the repository - run: | - ls ${{ gitea.workspace }} - - run: echo "🍏 This job's status is ${{ job.status }}." diff --git a/Cargo.lock b/Cargo.lock deleted file mode 100644 index 51973f4..0000000 --- a/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "small-rust" -version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml deleted file mode 100644 index 8878772..0000000 --- a/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "small-rust" -version = "0.1.0" -edition = "2021" - -[dependencies] - -[profile.release] -lto = true -codegen-units = 1 -strip = "symbols" diff --git a/docker-compose.yml b/docker-compose.yml index 26a21c6..773564e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,10 +1,4 @@ services: - small-rust-distroless: - build: - dockerfile: ./docker/distroless.Dockerfile - small-rust-alpine: + lua-alpine: build: dockerfile: ./docker/alpine.Dockerfile - small-rust-scratch: - build: - dockerfile: ./docker/scratch.Dockerfile diff --git a/docker/alpine.Dockerfile b/docker/alpine.Dockerfile index 99db98f..62b3ee7 100755 --- a/docker/alpine.Dockerfile +++ b/docker/alpine.Dockerfile @@ -1,56 +1,10 @@ -#################################################################################################### -## Builder -#################################################################################################### -FROM rust:1-alpine3.19 -# This is important, see https://github.com/rust-lang/docker-rust/issues/85 -ENV RUSTFLAGS="-C target-feature=-crt-static" +FROM alpine:3.20 -RUN apk add --no-cache musl-dev +RUN apk add --update lua5.3 && \ + rm -rf /var/cache/apk/* /tmp/* WORKDIR /app COPY ./ /app -RUN cargo build --release -RUN strip target/release/small-rust - -#################################################################################################### -## Final image -#################################################################################################### -FROM alpine:3.19 - -RUN apk add --no-cache libgcc - -COPY --from=0 /app/target/release/small-rust . - -ENTRYPOINT ["/small-rust"] - - -#################################################################################################### -## Alternatively use this builder -#################################################################################################### -#FROM rust:latest AS builder -# -#RUN rustup target add x86_64-unknown-linux-musl -#RUN apt update && apt install -y musl-tools musl-dev -#RUN update-ca-certificates -# -## Create appuser -#ENV USER=small-rust -#ENV UID=10001 -# -#RUN adduser \ -# --disabled-password \ -# --gecos "" \ -# --home "/nonexistent" \ -# --shell "/sbin/nologin" \ -# --no-create-home \ -# --uid "${UID}" \ -# "${USER}" -# -# -#WORKDIR /app -# -#COPY ./ . -# -#RUN cargo build --target x86_64-unknown-linux-musl --release +CMD ["/usr/bin/lua5.3", "src/main.lua"] diff --git a/docker/distroless.Dockerfile b/docker/distroless.Dockerfile deleted file mode 100644 index ada35b6..0000000 --- a/docker/distroless.Dockerfile +++ /dev/null @@ -1,46 +0,0 @@ -#################################################################################################### -## Builder -#################################################################################################### -FROM rust:latest AS builder - -RUN update-ca-certificates - -# Create appuser -ENV USER=small-rust -ENV UID=10001 - -RUN adduser \ - --disabled-password \ - --gecos "" \ - --home "/nonexistent" \ - --shell "/sbin/nologin" \ - --no-create-home \ - --uid "${UID}" \ - "${USER}" - - -WORKDIR /app - -COPY ./ . - -# We no longer need to use the x86_64-unknown-linux-musl target -RUN cargo build --release - -#################################################################################################### -## Final image -#################################################################################################### -FROM gcr.io/distroless/cc - -# Import from builder. -COPY --from=builder /etc/passwd /etc/passwd -COPY --from=builder /etc/group /etc/group - -WORKDIR /app - -# Copy our build -COPY --from=builder /app/target/release/small-rust ./ - -# Use an unprivileged user. -USER small-rust:small-rust - -CMD ["/app/small-rust"] diff --git a/docker/scratch.Dockerfile b/docker/scratch.Dockerfile deleted file mode 100755 index 73b87b8..0000000 --- a/docker/scratch.Dockerfile +++ /dev/null @@ -1,76 +0,0 @@ -#################################################################################################### -## Builder -#################################################################################################### -FROM rust:latest AS builder - -RUN rustup target add x86_64-unknown-linux-musl -RUN apt update && apt install -y musl-tools musl-dev -RUN update-ca-certificates - -# Create appuser -ENV USER=small-rust -ENV UID=10001 - -RUN adduser \ - --disabled-password \ - --gecos "" \ - --home "/nonexistent" \ - --shell "/sbin/nologin" \ - --no-create-home \ - --uid "${UID}" \ - "${USER}" - - -WORKDIR /app - -COPY ./ . - -RUN cargo build --target x86_64-unknown-linux-musl --release - -#################################################################################################### -## Final image -#################################################################################################### -FROM scratch - -# Import from builder. -COPY --from=builder /etc/passwd /etc/passwd -COPY --from=builder /etc/group /etc/group - -WORKDIR /app - -# Copy our build -COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/small-rust ./ - -# Use an unprivileged user. -USER small-rust:small-rust - -CMD ["/app/small-rust"] - -#################################################################################################### -## Alternatively use this builder (image size actually bigger) -#################################################################################################### -#FROM rust:1-alpine3.19 AS builder -# -#RUN rustup update nightly; rustup default nightly; -# -## Create appuser -#ENV USER=small-rust -#ENV UID=10001 -# -#RUN adduser \ -# --disabled-password \ -# --gecos "" \ -# --home "/nonexistent" \ -# --shell "/sbin/nologin" \ -# --no-create-home \ -# --uid "${UID}" \ -# "${USER}" -# -#RUN apk add --no-cache musl-dev -# -#WORKDIR /app -# -#COPY ./ /app -# -#RUN cargo build --release -# diff --git a/src/main.lua b/src/main.lua new file mode 100644 index 0000000..2220df5 --- /dev/null +++ b/src/main.lua @@ -0,0 +1 @@ +io.write("Hello world\n") diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -}