From 18a1c677c7de9109264d73d9ec147f6f013d8400 Mon Sep 17 00:00:00 2001 From: LucifersCircle Date: Fri, 29 Nov 2024 03:02:12 -0800 Subject: [PATCH] I hate workflows Lets see if gpt can fix it --- .github/workflows/build-and-push.yml | 47 +++++++++++++--------------- Dockerfile | 33 +++++++++++++------ 2 files changed, 44 insertions(+), 36 deletions(-) diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml index 8331366..a905af6 100644 --- a/.github/workflows/build-and-push.yml +++ b/.github/workflows/build-and-push.yml @@ -1,39 +1,34 @@ -name: Build and Push Docker Image +name: Build and Deploy Docker Image on: push: branches: - main - workflow_dispatch: # Allows manual trigger - -env: - REGISTRY_IMAGE: luciferscircle/redlib + workflow_dispatch: jobs: - build-and-push: + build: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v3 + - name: Checkout repository + uses: actions/checkout@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 - - name: Log in to DockerHub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-docker-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-docker- - - name: Build and push Docker image - uses: docker/build-push-action@v5 - with: - context: . - platforms: linux/amd64 - push: true - tags: | - ${{ env.REGISTRY_IMAGE }}:latest - ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} - build-args: | - TARGET=x86_64-unknown-linux-musl + - name: Build Docker image + run: | + docker build --file Dockerfile --tag luciferscircle/webos-token-refresh . + + - name: Push Docker image + run: | + docker push luciferscircle/webos-token-refresh diff --git a/Dockerfile b/Dockerfile index 487f737..189b8b6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,36 @@ -FROM rust:1.71.0-alpine +# Use an Alpine-based image as the base +FROM rust:1.71.0-alpine3.19 AS build -# Install git and other necessary dependencies using apk -RUN apk update && apk add --no-cache git +# Install necessary dependencies (git, curl, etc.) +RUN apk add --no-cache git curl build-base -# Set the working directory to /build +# Set the working directory for the build process WORKDIR /build -# Clone the redlib repository -RUN git clone https://github.com/LucifersCircle/redlib.git /build +# Clone the repository +RUN git clone https://github.com/LucifersCircle/redlib.git . -# Checkout the main branch -RUN cd /build && git checkout main +# Build the project using Cargo +RUN cargo build --release -# Set the final image's default user +# Final image with only the necessary runtime dependencies +FROM alpine:3.19 + +# Install dependencies needed to run the binary (curl, for healthcheck) +RUN apk add --no-cache curl + +# Copy the compiled binary from the build stage +COPY --from=build /build/target/release/redlib /usr/local/bin/ + +# Add a user to run the application RUN adduser --home /nonexistent --no-create-home --disabled-password redlib USER redlib # Expose the necessary port EXPOSE 8080 -# Set the default command to run the application +# Run a healthcheck to ensure the app is working +HEALTHCHECK --interval=1m --timeout=3s CMD wget --spider -q http://localhost:8080/settings || exit 1 + +# Set the default command to run the redlib binary CMD ["redlib"]