123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- name: Java Deploy with Maven
- on:
- push:
- branches: [ master ]
- tags: [release-v*]
- jobs:
- build:
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v4
- with:
- persist-credentials: false
-
- - name: Set up JDK 11
- # 这里使用java11的环境, 其他项目在github action中找到对应的语言环境就行
- uses: actions/setup-java@v2
- with:
- java-version: 11
- distribution: 'adopt'
-
- - name: Build with Maven
- # 这里maven的打包命令, 其他项目修改为对应的打包命令
- run: |
- mvn package
- - name: Push Docker
- run: |
- docker login --username=${{ secrets.USERNAME }} --password ${{ secrets.PASSWORD }} registry.cn-shanghai.aliyuncs.com
- docker build . -t ${{ secrets.REGISTRY }}:$GITHUB_RUN_NUMBER
- docker push ${{ secrets.REGISTRY }}:$GITHUB_RUN_NUMBER
- docker tag $(docker images ${{ secrets.REGISTRY }}:$GITHUB_RUN_NUMBER -q) ${{ secrets.REGISTRY }}:latest
- docker push ${{ secrets.REGISTRY }}:latest
- pull-docker:
- needs: [build]
- name: Pull Docker
- runs-on: ubuntu-latest
- steps:
- - name: Deploy
- uses: appleboy/ssh-action@master
- with:
- host: ${{ secrets.HOST }}
- username: ${{ secrets.USER }}
- password: ${{ secrets.PWD }}
- port: ${{ secrets.PORT }}
- script: |
- docker stop $(docker ps --filter ancestor=${{ secrets.REGISTRY }} -q)
- docker rm -f $(docker ps -a --filter ancestor=${{ secrets.REGISTRY }}:latest -q)
- docker rmi -f $(docker images ${{ secrets.REGISTRY }}:latest -q)
- docker login --username=${{ secrets.USERNAME }} --password ${{ secrets.PASSWORD }} registry.cn-shanghai.aliyuncs.com
- docker pull ${{ secrets.REGISTRY }}:latest
- docker run -d -p 8060:8060 ${{ secrets.REGISTRY }}:latest
|