diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..77973b35 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "npm" + directory: "/materialious" + schedule: + interval: "weekly" diff --git a/.github/workflows/prod-vite.yml b/.github/workflows/prod-vite.yml new file mode 100644 index 00000000..c3af543e --- /dev/null +++ b/.github/workflows/prod-vite.yml @@ -0,0 +1,35 @@ +name: Production Vite workflow + +on: + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./materialious + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + context: ./materialious + push: true + tags: wardpearce/materialious:latest diff --git a/README.md b/README.md index 0f959003..c311e6f1 100644 --- a/README.md +++ b/README.md @@ -24,12 +24,10 @@ - Dash support. - Chapters. - Audio only mode. +- Playlists. - PWA support. ## Todo -- Docker building & publishing workflow. -- Launching 'materialio.us'. -- Locking down git branches & setup PR requirements. - Localization. ## Previews diff --git a/materialious/Dockerfile b/materialious/Dockerfile new file mode 100644 index 00000000..0813d74f --- /dev/null +++ b/materialious/Dockerfile @@ -0,0 +1,41 @@ +# Specify the base image +FROM node AS builder + +# Set the working directory +WORKDIR /app + +# Copy package.json and package-lock.json to the working directory +COPY package*.json ./ + +# Copy the rest of the project files to the working directory +COPY . . + +# Create placeholder env vars +RUN echo "VITE_DEFAULT_INVIDIOUS_INSTANCE=VITE_DEFAULT_INVIDIOUS_INSTANCE_PLACEHOLDER" > .env && \ + echo "VITE_DEFAULT_FRONTEND_URL=VITE_DEFAULT_FRONTEND_URL_PLACEHOLDER" > .env && \ + echo "VITE_DEFAULT_SPONSERBLOCK_INSTANCE=VITE_DEFAULT_SPONSERBLOCK_INSTANCE_PLACEHOLDER" > .env && \ + echo "VITE_DEFAULT_RETURNYTDISLIKES_INSTANCE=VITE_DEFAULT_RETURNYTDISLIKES_INSTANCE_PLACEHOLDER" >> .env + +# Install dependencies and build the project +RUN npm install && npm run build + +FROM nginx:alpine + +# Remove the default nginx configuration +RUN rm /etc/nginx/conf.d/default.conf + +# Copy the nginx.conf file to the container +COPY nginx.conf /etc/nginx/nginx.conf + +# Copy the built Vite project from the builder stage +COPY --from=builder /app/dist /usr/share/nginx/html + +# Expose the desired port +EXPOSE 80 + +# Copy the replace_env_vars.sh script +COPY replace_env_vars.sh /replace_env_vars.sh +RUN chmod +x /replace_env_vars.sh + +# Replace env vars & Start nginx +CMD ["/bin/sh", "-c", "/replace_env_vars.sh && nginx -g \"daemon off;\""] \ No newline at end of file diff --git a/materialious/nginx.conf b/materialious/nginx.conf new file mode 100644 index 00000000..2984783a --- /dev/null +++ b/materialious/nginx.conf @@ -0,0 +1,17 @@ +events { + worker_connections 1024; +} + +http { + default_type application/octet-stream; + include /etc/nginx/mime.types; + + server { + listen 80; + + location / { + root /usr/share/nginx/html; + try_files $uri /index.html; + } + } +} \ No newline at end of file diff --git a/materialious/replace_env_vars.sh b/materialious/replace_env_vars.sh new file mode 100644 index 00000000..6e489d7e --- /dev/null +++ b/materialious/replace_env_vars.sh @@ -0,0 +1,8 @@ +#!/bin/sh +ROOT_DIR=./ + +# Replace env vars in JavaScript and HTML files served by NGINX +find "$ROOT_DIR" -type f \( -name "*.js" -o -name "*.html" \) -exec sed -i 's|VITE_DEFAULT_INVIDIOUS_INSTANCE_PLACEHOLDER|'"$VITE_DEFAULT_INVIDIOUS_INSTANCE"'|g' {} + +find "$ROOT_DIR" -type f \( -name "*.js" -o -name "*.html" \) -exec sed -i 's|VITE_DEFAULT_RETURNYTDISLIKES_INSTANCE_PLACEHOLDER|'"$VITE_DEFAULT_RETURNYTDISLIKES_INSTANCE"'|g' {} + +find "$ROOT_DIR" -type f \( -name "*.js" -o -name "*.html" \) -exec sed -i 's|VITE_DEFAULT_FRONTEND_URL_PLACEHOLDER|'"$VITE_DEFAULT_FRONTEND_URL"'|g' {} + +find "$ROOT_DIR" -type f \( -name "*.js" -o -name "*.html" \) -exec sed -i 's|VITE_DEFAULT_SPONSERBLOCK_INSTANCE_PLACEHOLDER|'"$VITE_DEFAULT_SPONSERBLOCK_INSTANCE"'|g' {} + \ No newline at end of file