Skip to content

Commit

Permalink
chore: add Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
renxia committed Feb 22, 2024
1 parent d07ce3a commit 81e4b19
Show file tree
Hide file tree
Showing 7 changed files with 604 additions and 404 deletions.
108 changes: 108 additions & 0 deletions .github/workflows/docker-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: deploy to docker hub

on:
push:
tags:
- "v*.*.*"
branches:
- 'master'

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ${{ secrets.REGISTRY }}
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}

jobs:
docker-deploy:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
-
uses: actions/setup-node@v4
with:
cache: "pnpm"

-
name: Setup timezone
uses: szenius/set-timezone@v1.2
with:
timezoneLinux: Asia/Shanghai

-
name: Install dependencies
run: |
pnpm install
pnpm build
rm -rf tmp
mkdir tmp
cp package.json tmp
cd tmp
npm install --omit dev
pnpm dlx @lzwme/fed-lint-helper rm -f "node_modules/**/{license,LICENSE,README.md,readme.md,.*,*.d.ts,*.flow,*.map}"
# -
# name: Set up QEMU
# uses: docker/setup-qemu-action@v3
# -
# name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3

-
name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
tags: |
# set latest tag for default branch
type=raw,value=latest,enable={{is_default_branch}}
# tag event
type=ref,enable=true,priority=600,prefix=,suffix=,event=tag
-
name: Login to Docker Hub
uses: docker/login-action@v3
with:
# registry: ghcr.io # 声明镜像源
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
-
name: Build and push
id: docker_build
uses: docker/build-push-action@v5
with:
context: .
# platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

# -
# name: Login to Docker Hub
# run: |
# docker login --username=${{ secrets.DOCKER_USERNAME }} --password ${{ secrets.DOCKER_PASSWORD }} ${{ env.REGISTRY }}
# -
# name: Build and push Docker Image
# run: |
# docker build -t ${{ env.REGISTRY }}/${{ steps.meta.outputs.tags }} -f Dockerfile .
# docker push ${{ env.REGISTRY }}/${{ steps.meta.outputs.tags }}

# -
# name: Deploy Docker App
# uses: appleboy/ssh-action@master
# env:
# TZ: Asia/Shanghai
# with:
# host: ${{ secrets.HOST }}
# username: ${{ secrets.HOST_USERNAME }}
# key: ${{ secrets.HOST_SSHKEY }}
# port: ${{ secrets.PORT }}
# script: |
# wget https://raw.githubusercontent.com/${{ env.IMAGE_NAME }}/master/docker/docker-compose.yml
# ls
# cat docker-compose.yml
# docker-compose down -v
# docker-compose up -d
9 changes: 3 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ jobs:
os:
- ubuntu-latest
- macos-latest
- windows-latest
# - windows-latest
node-version:
- 16
include:
node-version: 18
os: ubuntu-latest
- 18
name: Node ${{ matrix.node-version }} on ${{ matrix.os }}
steps:
- name: Checkout
Expand All @@ -40,7 +37,7 @@ jobs:

- uses: pnpm/action-setup@v2
with:
version: 7
version: 8

- name: Install dependencies
run: pnpm install --ignore-scripts
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ npm-debug.log*
/service-account-staging.json
/service-account.json
*.tgz
/tmp
/cache
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# FROM node:18-alpine as builder
# COPY package.json .npmrc /tmp/build/
# RUN set -x \
# && apk update \
# && npm i -g pnpm \
# && cd /tmp/build \
# && npm install --omit dev \
# && npx @lzwme/fed-lint-helper rm -f "node_modules/**/{license,LICENSE,README.md,readme.md,.*,*.d.ts,*.flow,*.map}"

FROM node:18-alpine As producton
LABEL maintainer="renxia <lzwy0820@qq.com>"

WORKDIR /app

COPY package.json .npmrc server.js ./
COPY public public
COPY tmp/node_modules node_modules

ENV TZ=Asia/Shanghai
# ENV DEBUG=0
ENV NODE_ENV=production
ENV PORT=8080
ENV NPM_REGISTRY_URL=https://registry.npmmirror.com
ENV ORIGIN=https://unpkg.com
ENV ENABLE_CLOUDFLARE=0
ENV CLOUDFLARE_EMAIL=''
ENV CLOUDFLARE_KEY=''

EXPOSE 8080/tcp

# RUN npm i -g pnpm --registry $NPM_REGISTRY_URL
# RUN pnpm install --prod --registry $NPM_REGISTRY_URL

RUN rm -rf /root/.cache \
&& rm -rf /root/.pnpm-store \
&& rm -rf /root/.local/share/pnpm/store/v3/files

ENTRYPOINT [ "node", "server.js"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
prepare:

```bash
git clone https://github.com/renxia/unpkg.git
git clone https://github.com/lzwme/unpkg.git
cd unpkg
pnpm i
cp .env.sample .env.local # and edit the env.local config for local development
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@
"pretty-bytes": "5.6.0"
},
"dependencies": {
"@babel/core": "^7.20.12",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
"@babel/plugin-proposal-optional-chaining": "^7.20.7",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-syntax-export-default-from": "^7.18.6",
"@babel/plugin-syntax-export-namespace-from": "^7.8.3",
"@babel/plugin-syntax-import-meta": "^7.10.4",
"@emotion/react": "^11.11.3",
"@reach/visually-hidden": "^0.18.0",
"cheerio": "^1.0.0-rc.12",
Expand All @@ -39,7 +31,7 @@
"mime": "^4.0.1",
"morgan": "^1.10.0",
"ndjson": "^2.0.0",
"pretty-bytes": "^6.1.1",
"pretty-bytes": "5.6.0",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand All @@ -55,6 +47,14 @@
},
"devDependencies": {
"@ampproject/rollup-plugin-closure-compiler": "^0.27.0",
"@babel/core": "^7.20.12",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
"@babel/plugin-proposal-optional-chaining": "^7.20.7",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-syntax-export-default-from": "^7.18.6",
"@babel/plugin-syntax-export-namespace-from": "^7.8.3",
"@babel/plugin-syntax-import-meta": "^7.10.4",
"@babel/preset-env": "^7.20.2",
"@babel/preset-react": "^7.18.6",
"@typescript-eslint/eslint-plugin": "7.0.2",
Expand All @@ -81,7 +81,7 @@
"@rollup/plugin-url": "^8.0.2",
"supertest": "^6.3.4"
},
"packageManager": "pnpm@7.26.0",
"packageManager": "pnpm@8.0.0",
"engines": {
"node": ">=12"
},
Expand Down
Loading

0 comments on commit 81e4b19

Please sign in to comment.