ci: Add github action for build and push
This commit is contained in:
4
.dockerignore
Normal file
4
.dockerignore
Normal file
@@ -0,0 +1,4 @@
|
||||
**/node_modules/
|
||||
**/.node/
|
||||
**/dist/
|
||||
**/pnpm-lock.yaml
|
||||
113
.github/workflows/build-and-push.yml
vendored
Normal file
113
.github/workflows/build-and-push.yml
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
name: build-and-push
|
||||
|
||||
run-name: 构建镜像并推送仓库 ${{ github.event.inputs.dockerImageTag }} (${{ github.event.inputs.registry }})
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
dockerImageTag:
|
||||
description: 'Docker Image Tag'
|
||||
default: 'v1.0.0-dev'
|
||||
required: true
|
||||
architecture:
|
||||
description: 'Architecture'
|
||||
required: true
|
||||
default: 'linux/amd64'
|
||||
type: choice
|
||||
options:
|
||||
- linux/amd64
|
||||
- linux/arm64
|
||||
- linux/amd64,linux/arm64
|
||||
registry:
|
||||
description: 'Push To Registry'
|
||||
required: true
|
||||
default: 'fit2cloud-registry'
|
||||
type: choice
|
||||
options:
|
||||
- fit2cloud-registry
|
||||
- dockerhub
|
||||
- dockerhub, fit2cloud-registry
|
||||
|
||||
jobs:
|
||||
build-and-push-to-fit2cloud-registry:
|
||||
if: ${{ contains(github.event.inputs.registry, 'fit2cloud') }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.ref_name }}
|
||||
- name: Prepare
|
||||
id: prepare
|
||||
run: |
|
||||
DOCKER_IMAGE=${{ secrets.FIT2CLOUD_REGISTRY_HOST }}/cordys/cordys-crm
|
||||
DOCKER_PLATFORMS=${{ github.event.inputs.architecture }}
|
||||
TAG_NAME=${{ github.event.inputs.dockerImageTag }}
|
||||
if [[ ${TAG_NAME} == *dev* ]]; then
|
||||
DOCKER_IMAGE_TAGS="--tag ${DOCKER_IMAGE}:${TAG_NAME}"
|
||||
else
|
||||
DOCKER_IMAGE_TAGS="--tag ${DOCKER_IMAGE}:${TAG_NAME} --tag ${DOCKER_IMAGE}:latest"
|
||||
fi
|
||||
echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} \
|
||||
--build-arg DOCKER_IMAGE_TAG=${{ github.event.inputs.dockerImageTag }} --build-arg BUILD_AT=$(TZ=Asia/Shanghai date +'%Y-%m-%dT%H:%M') --build-arg GITHUB_COMMIT=${GITHUB_SHA::8} --no-cache \
|
||||
${DOCKER_IMAGE_TAGS} .
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GH_TOKEN }}
|
||||
- name: Login to FIT2CLOUD Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ secrets.FIT2CLOUD_REGISTRY_HOST }}
|
||||
username: ${{ secrets.FIT2CLOUD_REGISTRY_USERNAME }}
|
||||
password: ${{ secrets.FIT2CLOUD_REGISTRY_PASSWORD }}
|
||||
- name: Docker Buildx (build-and-push)
|
||||
run: |
|
||||
docker buildx build --output "type=image,push=true" ${{ steps.prepare.outputs.buildx_args }} -f installer/Dockerfile
|
||||
|
||||
build-and-push-to-dockerhub:
|
||||
if: ${{ contains(github.event.inputs.registry, 'dockerhub') }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.ref_name }}
|
||||
- name: Prepare
|
||||
id: prepare
|
||||
run: |
|
||||
DOCKER_IMAGE=cordys/cordys-crm
|
||||
DOCKER_PLATFORMS=${{ github.event.inputs.architecture }}
|
||||
TAG_NAME=${{ github.event.inputs.dockerImageTag }}
|
||||
if [[ ${TAG_NAME} == *dev* ]]; then
|
||||
DOCKER_IMAGE_TAGS="--tag ${DOCKER_IMAGE}:${TAG_NAME}"
|
||||
else
|
||||
DOCKER_IMAGE_TAGS="--tag ${DOCKER_IMAGE}:${TAG_NAME} --tag ${DOCKER_IMAGE}:latest"
|
||||
fi
|
||||
echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} \
|
||||
--build-arg DOCKER_IMAGE_TAG=${{ github.event.inputs.dockerImageTag }} --build-arg BUILD_AT=$(TZ=Asia/Shanghai date +'%Y-%m-%dT%H:%M') --build-arg GITHUB_COMMIT=${GITHUB_SHA::8} --no-cache \
|
||||
${DOCKER_IMAGE_TAGS} .
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GH_TOKEN }}
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Docker Buildx (build-and-push)
|
||||
run: |
|
||||
docker buildx build --output "type=image,push=true" ${{ steps.prepare.outputs.buildx_args }} -f installer/Dockerfile
|
||||
32
Dockerfile
32
Dockerfile
@@ -1,17 +1,35 @@
|
||||
FROM node:22-slim AS frontend
|
||||
|
||||
WORKDIR /frontend
|
||||
COPY frontend /frontend
|
||||
RUN npm install -g pnpm && \
|
||||
pnpm install && \
|
||||
pnpm run build
|
||||
|
||||
|
||||
|
||||
FROM eclipse-temurin:21-jdk AS build
|
||||
WORKDIR /build
|
||||
COPY . /build
|
||||
COPY --from=frontend /frontend/packages/web/dist /build/frontend/packages/web/dist
|
||||
COPY --from=frontend /frontend/packages/mobile/dist /build/frontend/packages/mobile/dist
|
||||
RUN ./mvnw clean package -DskipTests -pl '!frontend' && \
|
||||
cd backend/crm/target/dependency && jar -xf ../*.jar
|
||||
|
||||
|
||||
|
||||
FROM registry.fit2cloud.com/metersphere/alpine-openjdk21-jre
|
||||
|
||||
LABEL maintainer="FIT2CLOUD <support@fit2cloud.com>"
|
||||
|
||||
ARG CRM_VERSION=main
|
||||
ARG MODULE=crm
|
||||
ARG DEPENDENCY=backend/${MODULE}/target/dependency
|
||||
ARG DEPENDENCY=/build/backend/${MODULE}/target/dependency
|
||||
|
||||
COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib
|
||||
COPY ${DEPENDENCY}/META-INF /app/META-INF
|
||||
COPY ${DEPENDENCY}/BOOT-INF/classes /app
|
||||
|
||||
# web
|
||||
COPY backend/${MODULE}/src/main/resources/packages /app/static
|
||||
COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib
|
||||
COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF
|
||||
COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app
|
||||
COPY --from=build /build/backend/${MODULE}/src/main/resources/packages /app/static
|
||||
|
||||
ENV JAVA_CLASSPATH=/app:/app/lib/*
|
||||
ENV JAVA_MAIN_CLASS=io.cordys.Application
|
||||
|
||||
1
frontend/.gitignore
vendored
1
frontend/.gitignore
vendored
@@ -25,3 +25,4 @@ coverage
|
||||
*.sw?
|
||||
|
||||
*.tsbuildinfo
|
||||
.node/
|
||||
|
||||
Reference in New Issue
Block a user