Browse Source

Update 'docker/.github/workflows/main.yml'

天问 2 years ago
parent
commit
c2b46e7b74
1 changed files with 49 additions and 0 deletions
  1. 49 0
      docker/.github/workflows/main.yml

+ 49 - 0
docker/.github/workflows/main.yml

@@ -0,0 +1,49 @@
+name: Java Deploy with Maven
+
+on:
+  push:
+    branches: [ master ]
+    tags: [release-v*]
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v2
+      - name: Set up JDK 11
+ # 这里使用java11的环境, 其他项目在github action中找到对应的语言环境就行
+        uses: actions/setup-java@v1
+        with:
+          java-version: 11
+      - 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