This commit is contained in:
@@ -8,49 +8,33 @@ on:
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
runs-on: xw-runner
|
||||
env:
|
||||
REGISTRY_URL: ${{ secrets.REGISTRY_URL }}
|
||||
IMAGE_NAME: ${{ secrets.IMAGE_NAME }}
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: https://github.com/actions/checkout@v4
|
||||
|
||||
- name: Set up JDK 17
|
||||
uses: https://github.com/actions/setup-java@v4
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: 17
|
||||
|
||||
- name: Build Jar
|
||||
run: mvn -B clean package -DskipTests
|
||||
uses: https://gitea.com/actions/checkout@v4
|
||||
|
||||
- name: Determine image tag
|
||||
id: vars
|
||||
run: |
|
||||
REGISTRY_URL='${{ secrets.REGISTRY_URL }}'
|
||||
IMAGE_NAME='${{ secrets.IMAGE_NAME }}'
|
||||
SHA=$(git rev-parse --short HEAD)
|
||||
echo "IMAGE_TAG=${REGISTRY_URL}/${IMAGE_NAME}:${SHA}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: https://github.com/docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to registry
|
||||
if: ${{ secrets.REGISTRY_USERNAME && secrets.REGISTRY_PASSWORD }}
|
||||
uses: https://github.com/docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ secrets.REGISTRY_URL }}
|
||||
username: ${{ secrets.REGISTRY_USERNAME }}
|
||||
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||
- name: Build Jar (in Maven container)
|
||||
run: |
|
||||
docker run --rm \
|
||||
-v "$PWD":/workspace \
|
||||
-w /workspace \
|
||||
maven:3.9.9-eclipse-temurin-17 \
|
||||
mvn -B clean package -DskipTests
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: https://github.com/docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
file: Dockerfile
|
||||
tags: ${{ steps.vars.outputs.IMAGE_TAG }}
|
||||
run: |
|
||||
docker build --pull -t "${{ steps.vars.outputs.IMAGE_TAG }}" .
|
||||
docker push "${{ steps.vars.outputs.IMAGE_TAG }}"
|
||||
|
||||
- name: Deploy to target host
|
||||
uses: https://github.com/appleboy/ssh-action@v0.1.5
|
||||
uses: https://gitea.com/appleboy/ssh-action@v0.1.5
|
||||
with:
|
||||
host: ${{ secrets.DEPLOY_HOST }}
|
||||
port: ${{ secrets.DEPLOY_PORT }}
|
||||
|
||||
Reference in New Issue
Block a user