Added Redlib
This commit is contained in:
parent
16159ef4c4
commit
013d9752ff
65
.gitea/workflows/redlib.yaml
Normal file
65
.gitea/workflows/redlib.yaml
Normal file
@ -0,0 +1,65 @@
|
||||
name: redlib
|
||||
run-name: redlib
|
||||
env:
|
||||
REPO_NAME: redlib
|
||||
REMOTE_REPO: https://github.com/redlib-org/redlib.git
|
||||
BUILD_PLATFORM: linux/arm64
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 0 * * *" # at midnight
|
||||
push:
|
||||
paths:
|
||||
- ".gitea/workflows/redlib.yaml"
|
||||
|
||||
jobs:
|
||||
build-redlib:
|
||||
runs-on: runner
|
||||
container:
|
||||
image: git.opnxng.com/opnxng/docker-buildx:latest
|
||||
steps:
|
||||
- name: Check latest upstream commit
|
||||
run: |
|
||||
STORED_COMMIT=$(curl -H "Authorization: Bearer ${{ secrets.NT }}" -s "https://nt.opnxng.com/${REPO_NAME}/raw?poll=1" | tail -n 1)
|
||||
LATEST_COMMIT=$(git ls-remote ${REMOTE_REPO} | awk '{print $1}' | head -1)
|
||||
echo "STORED_COMMIT=${STORED_COMMIT}" >> "$GITHUB_ENV"
|
||||
echo "LATEST_COMMIT=${LATEST_COMMIT}" >> "$GITHUB_ENV"
|
||||
echo "Stored Commit: ${STORED_COMMIT}"
|
||||
echo "Latest Commit: ${LATEST_COMMIT}"
|
||||
|
||||
- name: Build and push Docker image
|
||||
run: |
|
||||
if [ "$STORED_COMMIT" != "$LATEST_COMMIT" ]; then
|
||||
echo "Found a new commit, building new image"
|
||||
# Create and use Docker Buildx builder
|
||||
docker buildx create --use --name buildx
|
||||
# Login to Package Registry
|
||||
echo "${{ secrets.TOKEN }}" | docker login git.opnxng.com -u ${{ gitea.repository_owner }} --password-stdin
|
||||
# Build and push Docker image
|
||||
mkdir temp
|
||||
cd temp
|
||||
curl -JL https://git.opnxng.com/opnxng/docker-images/raw/branch/main/dockerfiles/redlib.Dockerfile -o Dockerfile
|
||||
docker buildx build \
|
||||
--platform ${BUILD_PLATFORM} \
|
||||
-t git.opnxng.com/${{ gitea.repository_owner }}/${REPO_NAME}:latest \
|
||||
-f ./Dockerfile \
|
||||
--push . && \
|
||||
curl -H prio:low -d "Built and pushed ${REPO_NAME}" https://ntfy.opnxng.com/build || \
|
||||
{ curl -H tags:warning -H prio:high -d "Built and pushed ${REPO_NAME} failed!" https://ntfy.opnxng.com/build ; exit 1; }
|
||||
# Remove Docker Buildx builder
|
||||
docker buildx rm buildx
|
||||
else
|
||||
echo "No new commit, skipped build"
|
||||
fi
|
||||
|
||||
- name: Update stored commit
|
||||
run: |
|
||||
if [ "$STORED_COMMIT" != "$LATEST_COMMIT" ]; then
|
||||
curl -H "Authorization: Bearer ${{ secrets.NT }}" -d $(git ls-remote ${REMOTE_REPO} | awk '{print $1}' | head -1) "https://nt.opnxng.com/${REPO_NAME}"
|
||||
STORED_COMMIT=$(curl -H "Authorization: Bearer ${{ secrets.NT }}" -s "https://nt.opnxng.com/${REPO_NAME}/raw?poll=1" | tail -n 1)
|
||||
echo "STORED_COMMIT=${STORED_COMMIT}" >> "$GITHUB_ENV"
|
||||
else
|
||||
curl -H "Authorization: Bearer ${{ secrets.NT }}" -d $(git ls-remote ${REMOTE_REPO} | awk '{print $1}' | head -1) "https://nt.opnxng.com/${REPO_NAME}"
|
||||
STORED_COMMIT=$(curl -H "Authorization: Bearer ${{ secrets.NT }}" -s "https://nt.opnxng.com/${REPO_NAME}/raw?poll=1" | tail -n 1)
|
||||
echo "STORED_COMMIT=${STORED_COMMIT}" >> "$GITHUB_ENV"
|
||||
exit 1
|
||||
fi
|
38
dockerfiles/redlib.Dockerfile
Normal file
38
dockerfiles/redlib.Dockerfile
Normal file
@ -0,0 +1,38 @@
|
||||
# Stage 1: Build the redlib binary
|
||||
FROM rust:alpine3.19 AS builder
|
||||
|
||||
ARG TARGET=aarch64-unknown-linux-musl
|
||||
|
||||
# Install necessary packages for building the application
|
||||
RUN apk add --no-cache curl git musl-dev
|
||||
|
||||
# Clone the redlib repository and build
|
||||
RUN git clone https://github.com/redlib-org/redlib && \
|
||||
cd redlib && \
|
||||
sed -i 's/#9a0000/#4385BE/g' static/themes/light.css && \
|
||||
sed -i 's/#9a0000/#205EA6/g' static/themes/black.css && \
|
||||
sed -i 's/red/#205EA6/g' static/themes/dark.css && \
|
||||
cargo build --release --target=${TARGET} && \
|
||||
cp target/${TARGET}/release/redlib /usr/local/bin/redlib && \
|
||||
cd .. && \
|
||||
rm -rf redlib
|
||||
|
||||
# Stage 2: Create the final image
|
||||
FROM alpine:3.19
|
||||
|
||||
RUN apk add --no-cache curl
|
||||
|
||||
# Create a non-root user
|
||||
RUN adduser --home /nonexistent --no-create-home --disabled-password redlib
|
||||
|
||||
# Copy the compiled binary from the builder stage
|
||||
COPY --from=builder /usr/local/bin/redlib /usr/local/bin/redlib
|
||||
|
||||
# Tell Docker to expose port 8080
|
||||
EXPOSE 8080
|
||||
|
||||
# Run a healthcheck every minute to make sure redlib is functional
|
||||
HEALTHCHECK --interval=1m --timeout=3s CMD wget --spider -q http://localhost:8080/settings || exit 1
|
||||
|
||||
USER redlib
|
||||
CMD ["redlib"]
|
Loading…
Reference in New Issue
Block a user