gh workflow

This commit is contained in:
typescreep
2025-06-09 15:18:02 +03:00
parent e575c86af4
commit ca465b8658
3 changed files with 70 additions and 21 deletions

40
.github/workflows/docker-build.yml vendored Normal file
View File

@@ -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 }}

30
Dockerfile.build Normal file
View File

@@ -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"]

View File

@@ -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;"]