From 6fee4a697e945ecbd07f0c3a7f4c83853d414971 Mon Sep 17 00:00:00 2001 From: Opnxng Date: Thu, 8 Aug 2024 21:33:09 +0800 Subject: [PATCH] Added Offtiktokapi --- .gitea/workflows/etherpad.yaml | 2 +- .gitea/workflows/offtiktokapi.yaml | 69 +++++++++++++++++++++++++++++ dockerfiles/ansible.Dockerfile | 2 +- dockerfiles/offtiktokapi.Dockerfile | 30 +++++++++++++ 4 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 .gitea/workflows/offtiktokapi.yaml create mode 100644 dockerfiles/offtiktokapi.Dockerfile diff --git a/.gitea/workflows/etherpad.yaml b/.gitea/workflows/etherpad.yaml index 1eadb40..915aa0d 100644 --- a/.gitea/workflows/etherpad.yaml +++ b/.gitea/workflows/etherpad.yaml @@ -63,4 +63,4 @@ jobs: 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 \ No newline at end of file + fi diff --git a/.gitea/workflows/offtiktokapi.yaml b/.gitea/workflows/offtiktokapi.yaml new file mode 100644 index 0000000..3324432 --- /dev/null +++ b/.gitea/workflows/offtiktokapi.yaml @@ -0,0 +1,69 @@ +name: offtiktokapi +run-name: offtiktokapi +env: + REPO_NAME: offtiktokapi + REMOTE_REPO: https://github.com/MarsHeer/offtiktokapi.git + BUILD_PLATFORM: linux/arm64 +on: + schedule: + - cron: "0 0 * * *" # at midnight + push: + paths: + - ".gitea/workflows/offtiktokapi.yaml" + +jobs: + build: + 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 + git clone ${REMOTE_REPO} . + # Create .env file + echo 'DATABASE_URL="file:../prisma/dev.db"' > .env + # Switch to node:slim as base image + curl -JL https://git.opnxng.com/opnxng/docker-images/raw/branch/main/dockerfiles/offtiktokapi.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 diff --git a/dockerfiles/ansible.Dockerfile b/dockerfiles/ansible.Dockerfile index 37e2797..3555a69 100755 --- a/dockerfiles/ansible.Dockerfile +++ b/dockerfiles/ansible.Dockerfile @@ -41,4 +41,4 @@ RUN echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen RUN echo "LANG=en_US.UTF-8" > /etc/locale.conf RUN locale-gen en_US.UTF-8 -ENV ANSIBLE_FORCE_COLOR true \ No newline at end of file +ENV ANSIBLE_FORCE_COLOR true diff --git a/dockerfiles/offtiktokapi.Dockerfile b/dockerfiles/offtiktokapi.Dockerfile new file mode 100644 index 0000000..db66b57 --- /dev/null +++ b/dockerfiles/offtiktokapi.Dockerfile @@ -0,0 +1,30 @@ +# Use an official Node.js slim base image +FROM node:slim + +RUN apt-get update && apt-get install -y --no-install-recommends \ + openssl \ + && rm -rf /var/lib/apt/lists/* + +# Set environment variables +ENV DEBIAN_FRONTEND=noninteractive + +# Create app directory +WORKDIR /usr/src/app + +# Copy project files +COPY . . + +# Install project dependencies +RUN npm install + +# Build the project +RUN npx prisma generate && npx prisma migrate dev + +RUN npx tsc --noEmit + + +# Expose the port the app runs on +EXPOSE 2000 + +# Define the command to run the application +CMD ["npm", "run", "start"]