65 lines
1.9 KiB
YAML
65 lines
1.9 KiB
YAML
name: JT808 CI/CD
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
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
|
|
|
|
- name: Determine image tag
|
|
id: vars
|
|
run: |
|
|
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 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 }}
|
|
|
|
- name: Deploy to target host
|
|
uses: https://github.com/appleboy/ssh-action@v0.1.5
|
|
with:
|
|
host: ${{ secrets.DEPLOY_HOST }}
|
|
port: ${{ secrets.DEPLOY_PORT }}
|
|
username: ${{ secrets.DEPLOY_USER }}
|
|
key: ${{ secrets.DEPLOY_PRIVATE_KEY }}
|
|
script: |
|
|
docker pull ${{ steps.vars.outputs.IMAGE_TAG }}
|
|
docker stop jt808-server || true
|
|
docker rm jt808-server || true
|
|
docker run -d --name jt808-server -p 8080:8080 -p 20048:20048 ${{ steps.vars.outputs.IMAGE_TAG }}
|
|
|