From c2ae6432ae4fc506a2adfa5d9196d4be304e2479 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Wed, 13 Sep 2023 23:08:44 +0200 Subject: [PATCH] add CI stuff --- .dockerignore | 7 +++++ .github/workflows/linting.yml | 52 +++++++++++++++++++++++++++++++++ .github/workflows/publish.yml | 55 +++++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 30 +++++++++++++++++++ Dockerfile | 19 ++++++++++++ README.md | 5 ++++ package-lock.json | 1 - package.json | 2 +- 8 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/linting.yml create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/release.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2d6b407 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +node_modules +*.log* +.nitro +.cache +.output +.env +dist diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml new file mode 100644 index 0000000..81e89e9 --- /dev/null +++ b/.github/workflows/linting.yml @@ -0,0 +1,52 @@ +name: Linting and Testing + +on: + push: + branches: + - master + - dev + pull_request: + +jobs: + linting: + name: Run Linters + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: 18 + cache: 'npm' + + - name: Install npm packages + run: npm install + + - name: Prepare for linting + run: npm run prepare + + - name: Run ESLint + run: npm lint + + building: + name: Build project + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: 18 + cache: 'npm' + + - name: Install npm packages + run: npm install + + - name: Build Project + run: npm build diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..3308cf9 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,55 @@ +name: Docker Publish + +on: + push: + branches: + - master + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v2 + + - name: Get version + id: package-version + uses: martinbeentjes/npm-get-version-action@main + + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + flavor: | + latest=auto + tags: | + type=semver,pattern={{version}},value=v${{ steps.package-version.outputs.current-version }} + + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@v4 + with: + push: true + context: . + labels: ${{ steps.meta.outputs.labels }} + tags: ${{ steps.meta.outputs.tags }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..04eeb1c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,30 @@ +name: Release + +on: + push: + branches: + - master + +jobs: + release: + name: Release + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Get version + id: package-version + uses: martinbeentjes/npm-get-version-action@main + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: v${{ steps.package-version.outputs.current-version }} + release_name: Bot v${{ steps.package-version.outputs.current-version }} + draft: false + prerelease: false diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8740677 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM node:18-alpine as base +WORKDIR /app + +# Build layer +FROM base as build + +COPY package-lock.json package.json ./ +RUN npm install --frozen-lockfile +COPY . . +RUN npm run build + +# Production layer +FROM base as production + +EXPOSE 3000 +ENV NODE_ENV=production +COPY --from=build /app/.output ./.output + +CMD ["node", ".output/server/index.mjs"] diff --git a/README.md b/README.md index 8bdc37b..68e7ceb 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,8 @@ features: supported platforms: - cloudflare workers - nodejs + +## Todos: + - [ ] release with multi platform + - [ ] Easy deploy to cloudflare button (just needs CI) + - [ ] Test on cloudflare diff --git a/package-lock.json b/package-lock.json index 1142de8..686ff56 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,6 @@ "name": "simple-proxy", "version": "2.0.0", "dependencies": { - "h3": "^1.8.1", "nitropack": "latest" }, "devDependencies": { diff --git a/package.json b/package.json index 7202444..b20a234 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "prepare": "nitropack prepare", "dev": "nitropack dev", "build": "nitropack build", - "preview": "node .output/server/index.mjs", + "start": "node .output/server/index.mjs", "lint": "eslint --ext .js src/", "lint:fix": "eslint --fix --ext .js src/" },