From ca465b86583dcba8675bd2dc4c6bd72cbfee083d Mon Sep 17 00:00:00 2001 From: typescreep Date: Mon, 9 Jun 2025 15:18:02 +0300 Subject: [PATCH] gh workflow --- .github/workflows/docker-build.yml | 40 ++++++++++++++++++++++++++++++ Dockerfile.build | 30 ++++++++++++++++++++++ Dockerfile.local | 21 ---------------- 3 files changed, 70 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/docker-build.yml create mode 100644 Dockerfile.build delete mode 100644 Dockerfile.local diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..193314d --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,40 @@ +name: release +on: + push: + branches: + - '*' + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' + - 'v[0-9]+.[0-9]+.[0-9]+rc[0-9]+' + +env: + NODE_VERSION: 20.18.1 + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - uses: benjlevesque/short-sha@v3.0 + id: short-sha + with: + length: 8 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + file: ./Dockerfile.build + builder: default + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ secrets.DOCKERHUB_USERNAME }}/openapi-ui:${{ github.head_ref || github.ref_name }}-${{ steps.short-sha.outputs.sha } + build-args: | + NODE_VERSION=${{ env.NODE_VERSION }} diff --git a/Dockerfile.build b/Dockerfile.build new file mode 100644 index 0000000..4214830 --- /dev/null +++ b/Dockerfile.build @@ -0,0 +1,30 @@ +ARG NODE_VERSION=20.18.1 + +FROM node:${NODE_VERSION}-alpine AS builder +WORKDIR /src +ENV PATH=/src/node_modules/.bin:$PATH + +COPY package.json package-lock.json ./ +RUN npm install +COPY . . +RUN npm run build + +FROM node:${NODE_VERSION}-alpine AS builder2 +WORKDIR /src +ENV PATH=/src/node_modules/.bin:$PATH + +COPY ./server/package.json ./ +COPY ./server/package-lock.json ./ +RUN npm install +COPY server server +COPY tsconfig.server.json ./ +COPY --from=builder /src/build /src/build +RUN npm run server:build + +FROM node:${NODE_VERSION}-alpine +WORKDIR /app +COPY --from=builder2 /src/node_modules /app/node_modules +COPY --from=builder2 /src/build /app/build +EXPOSE 8080 +USER 1001 +CMD ["node", "/app/build/index.js"] diff --git a/Dockerfile.local b/Dockerfile.local deleted file mode 100644 index de4d203..0000000 --- a/Dockerfile.local +++ /dev/null @@ -1,21 +0,0 @@ -FROM node:21.6.1-alpine3.19 AS builder - -WORKDIR /app - -COPY package.json package-lock.json ./ -RUN npm i -COPY . . -RUN npm run build - -FROM nginxinc/nginx-unprivileged:1.25.3 - -COPY --from=builder /app/build /usr/share/nginx/html/openapi-ui -COPY deploy/ / - -USER root -RUN chmod g+rw -R /run /usr/share/nginx/html \ - && chown root:root /usr/share/nginx/html - -USER 1001 - -CMD ["nginx", "-g", "daemon off;"]