Compare commits
3 Commits
2a388f61e2
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
75c91821e9
|
|||
|
b468c79056
|
|||
|
5475ee8878
|
@@ -84,3 +84,40 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
- name: Run tailwindcss
|
||||
run: tailwindcss --input style/tailwind.css
|
||||
|
||||
docker-build:
|
||||
runs-on: ubuntu-latest-docker
|
||||
permissions:
|
||||
packages: write
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
- name: Login to Gitea container registry
|
||||
uses: docker/login-action@v4
|
||||
with:
|
||||
registry: ${{ env.registry }}
|
||||
username: ${{ env.actions_user }}
|
||||
password: ${{ secrets.CONTAINER_REGISTRY_TOKEN }}
|
||||
- name: Get Image Name
|
||||
id: get-image-name
|
||||
run: |
|
||||
echo "IMAGE_NAME=$(echo ${{ env.registry }}/${{ gitea.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v6
|
||||
with:
|
||||
images: ${{ steps.get-image-name.outputs.IMAGE_NAME }}
|
||||
tags: |
|
||||
type=sha
|
||||
type=ref,event=branch
|
||||
type=raw,value=latest,enable={{is_default_branch}}
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v7
|
||||
with:
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
||||
99
Dockerfile
Normal file
99
Dockerfile
Normal file
@@ -0,0 +1,99 @@
|
||||
FROM rust:slim AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install a few dependencies
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends \
|
||||
git \
|
||||
curl \
|
||||
unzip && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN rustup target add wasm32-unknown-unknown
|
||||
|
||||
# Install dioxus-cli
|
||||
RUN curl -sSL https://dioxus.dev/install.sh | bash
|
||||
|
||||
ENV DAISYUI_PATH=/opt/daisyui/daisyui/
|
||||
ENV DAISYUI_THEME_PATH=/opt/daisyui/theme/
|
||||
ENV NODE_PATH=$DAISYUI_PATH:$DAISYUI_THEME_PATH
|
||||
|
||||
# Install DaisyUI bundles
|
||||
RUN mkdir -p $DAISYUI_PATH $DAISYUI_THEME_PATH && \
|
||||
cd $DAISYUI_PATH && \
|
||||
curl -sLO https://github.com/saadeghi/daisyui/releases/latest/download/daisyui.js && \
|
||||
cd $DAISYUI_THEME_PATH && \
|
||||
curl -sLO https://github.com/saadeghi/daisyui/releases/latest/download/daisyui-theme.js
|
||||
|
||||
# Install Tailwind CSS CLI
|
||||
RUN curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64 && \
|
||||
install tailwindcss-linux-x64 /usr/local/bin/tailwindcss && \
|
||||
rm tailwindcss-linux-x64
|
||||
|
||||
# Include Rust binaries in PATH
|
||||
ENV PATH="/root/.cargo/bin:${PATH}"
|
||||
|
||||
# Copy project dependency manifests
|
||||
COPY Cargo.toml Cargo.lock Dioxus.toml /app/
|
||||
|
||||
# Create dummy files to force cargo to build the dependencies
|
||||
# main() content fixes "failed to find intrinsics to enable `clone_ref` function"
|
||||
# See https://github.com/trunk-rs/trunk/issues/951#issuecomment-2816819963
|
||||
RUN mkdir /app/src && \
|
||||
echo "fn main() { dioxus::logger::initialize_default(); }" > /app/src/main.rs && \
|
||||
echo "fn main() {}" > /app/src/build.rs
|
||||
|
||||
# Prebuild dependencies
|
||||
RUN dx build --release --locked --web
|
||||
|
||||
# Remove assets from the initial build
|
||||
RUN rm -rf /app/target/dx/libretunes/release/web/public
|
||||
|
||||
RUN rm -rf /app/src
|
||||
|
||||
COPY --exclude=assets/tailwind.css assets /app/assets
|
||||
COPY style /app/style
|
||||
COPY migrations /app/migrations
|
||||
COPY src /app/src
|
||||
|
||||
# Copy necessary git files for getting build version
|
||||
RUN mkdir /app/.git
|
||||
COPY .git/HEAD .git/refs /app/.git
|
||||
|
||||
# dx build will run tailwindcss anyways, but doing it first here is faster and clearer if it fails
|
||||
RUN tailwindcss --input style/tailwind.css --output assets/tailwind.css
|
||||
|
||||
# Touch files to force rebuild
|
||||
RUN touch /app/src/main.rs && touch /app/src/build.rs
|
||||
|
||||
# Actually build
|
||||
RUN dx build --release --locked --web
|
||||
|
||||
# Use ldd to list all dependencies of the server, then copy them to /app/libs
|
||||
RUN mkdir /app/libs && ldd /app/target/dx/libretunes/release/web/server | grep "=> /" | \
|
||||
awk '{print $3}' | xargs -I '{}' cp '{}' /app/libs
|
||||
|
||||
# Build the final image
|
||||
FROM scratch
|
||||
|
||||
LABEL license="MIT"
|
||||
LABEL description="LibreTunes, an open-source browser audio player and \
|
||||
library manager built for collaborative listening."
|
||||
|
||||
# Copy the binary and assets to the final image
|
||||
COPY --from=builder /app/target/dx/libretunes/release/web/server /libretunes
|
||||
COPY --from=builder /app/target/dx/libretunes/release/web/public /public
|
||||
|
||||
ENV LIBRETUNES_SERVER_PUBLIC_PATH=/public
|
||||
ENV DIOXUS_PUBLIC_PATH=/public
|
||||
|
||||
# Copy libraries to /lib64
|
||||
COPY --from=builder /app/libs /lib64
|
||||
COPY --from=builder /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2
|
||||
|
||||
ENV LD_LIBRARY_PATH=/lib64
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
ENTRYPOINT [ "/libretunes" ]
|
||||
Reference in New Issue
Block a user