Skip to content

Commit

Permalink
build: up githun actions build_docker
Browse files Browse the repository at this point in the history
  • Loading branch information
zhpd committed May 20, 2023
1 parent 3019b65 commit e3df013
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 23 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/build_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ jobs:
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set node
uses: actions/setup-node@v3
with:
node-version: 18.x

- name: Build Web
id: build_web
run: |
npm i
npm run build
- name: Build Service
id: build_service
run: |
cd service
npm i
npm run build
cd ../
- name: Build and push
id: docker_build
uses: docker/build-push-action@v4
Expand Down
52 changes: 29 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
# build front-end
FROM node:lts-alpine AS frontend
# # build front-end
# FROM node:lts-alpine AS frontend

WORKDIR /app
# WORKDIR /app

COPY . /app
COPY ./package.json /app
COPY ./package-lock.json /app
RUN npm install --registry=https://registry.npmmirror.com
RUN npm run build
# COPY . /app
# COPY ./package.json /app
# COPY ./package-lock.json /app
# RUN npm install --registry=https://registry.npmmirror.com
# RUN npm run build

RUN rm -rf ./node_modules
# RUN rm -rf ./node_modules

# build backend
FROM node:lts-alpine AS backend
# # build backend
# FROM node:lts-alpine AS backend

WORKDIR /app
# WORKDIR /app

COPY ./service /app
COPY ./service/package.json /app
COPY ./service/package-lock.json /app
RUN npm install --registry=https://registry.npmmirror.com
RUN npm run build
# COPY ./service /app
# COPY ./service/package.json /app
# COPY ./service/package-lock.json /app
# RUN npm install --registry=https://registry.npmmirror.com
# RUN npm run build

RUN rm -rf ./node_modules
# RUN rm -rf ./node_modules

# service
FROM node:lts-alpine
Expand All @@ -32,14 +32,20 @@ RUN apk add --no-cache bash
RUN mkdir -p /app/log

WORKDIR /app
# copy front-end
COPY --from=frontend /app/.next/standalone /app/web
COPY --from=frontend /app/.next/static /app/web/.next/static
# # copy front-end -- 从docker构建中复制,运行太慢
# COPY --from=frontend /app/.next/standalone /app/web
# COPY --from=frontend /app/.next/static /app/web/.next/static
# COPY ./public /app/web/public
# copy .next/front -- 从源码构建结果中复制
COPY ./.next/standalone /app/web
COPY ./.next/static /app/web/.next/static
COPY ./public /app/web/public

WORKDIR /app/service
# copy backend
COPY --from=backend /app/dist /app/service/dist
# # copy backend -- 从docker构建中复制,运行太慢
# COPY --from=backend /app/dist /app/service/dist
# copy service/dist/backend -- 从源码构建结果中复制
COPY ./service/dist /app/service/dist

# start.sh
COPY ./docker-start.sh /app
Expand Down

0 comments on commit e3df013

Please sign in to comment.