MeterSphere/.github/workflows/build-push.yml

90 lines
2.9 KiB
YAML
Raw Normal View History

2020-12-03 14:41:42 +08:00
name: Build Docker Image and Push
on:
2020-12-03 19:18:08 +08:00
push:
branches:
2020-12-03 19:37:06 +08:00
- master
2022-04-14 19:29:16 +08:00
- dev
2022-02-16 23:36:31 +08:00
- v1*
- test-build
2020-12-03 19:37:06 +08:00
workflow_dispatch:
2022-02-16 23:36:31 +08:00
2020-12-03 14:41:42 +08:00
jobs:
2020-12-03 18:15:40 +08:00
build_push:
2020-12-03 14:41:42 +08:00
runs-on: ubuntu-latest
2020-12-03 18:15:40 +08:00
name: Build Docker Image and Push
2020-12-03 14:41:42 +08:00
steps:
2023-05-04 17:53:09 +08:00
- uses: actions/checkout@v3
2022-02-16 23:36:31 +08:00
with:
submodules: true
token: ${{ secrets.ACCESS_TOKEN }}
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v3.x
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Cache local Maven repository
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up JDK 11
2022-02-16 23:36:31 +08:00
uses: actions/setup-java@v1
with:
java-version: 11
2022-02-16 23:36:31 +08:00
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Unzip jar
2022-02-18 11:35:34 +08:00
run: mkdir -p backend/target/dependency && (cd backend/target/dependency; jar -xf ../*.jar)
2022-02-16 23:36:31 +08:00
- name: Prepare
id: prepare
run: |
DOCKER_IMAGE=metersphere/metersphere
DOCKER_PLATFORMS=linux/amd64,linux/arm64
TAG_NAME=${{ env.GITHUB_REF_SLUG }}
DOCKER_IMAGE_TAGS="--tag ${DOCKER_IMAGE}:${TAG_NAME} --tag ${DOCKER_IMAGE}:latest"
echo ::set-output name=docker_image::${DOCKER_IMAGE}
echo ::set-output name=version::${TAG_NAME}
echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} \
--build-arg VERSION=${TAG_NAME} \
--build-arg MS_VERSION=${{ env.GITHUB_REF_SLUG }}-${{ env.GITHUB_SHA_SHORT }} \
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--build-arg VCS_REF=${GITHUB_SHA::8} \
${DOCKER_IMAGE_TAGS} .
- name: Set up Docker Buildx
uses: crazy-max/ghaction-docker-buildx@v3
- name: Docker Buildx (build)
run: |
docker buildx build --output "type=image,push=false" ${{ steps.prepare.outputs.buildx_args }}
- name: Login to Registry
uses: docker/login-action@v1
with:
username: metersphere
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Docker Buildx (push)
run: |
docker buildx build --output "type=image,push=true" ${{ steps.prepare.outputs.buildx_args }}