|
| 1 | +name: Docker Image CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +env: |
| 10 | + DEPLOY_NAME: 'vidar-website' |
| 11 | + IMAGE_REPO: 'vidar-team/vidar-website' |
| 12 | + IMAGE_BASE: 'registry.cn-hangzhou.aliyuncs.com' |
| 13 | + |
| 14 | +jobs: |
| 15 | + build: |
| 16 | + if: github.repository == 'vidar-team/Vidar-Website' |
| 17 | + runs-on: ubuntu-latest |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout code |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Gen tag |
| 24 | + id: gen-tag |
| 25 | + run: | |
| 26 | + echo "tag=$(date +%s)" >> $GITHUB_OUTPUT |
| 27 | + echo "Generated tag: ${{ steps.gen-tag.outputs.tag }}" |
| 28 | +
|
| 29 | + - name: Build the Docker image |
| 30 | + run: | |
| 31 | + echo "Building Website image with tag: ${{ steps.gen-tag.outputs.tag }}" |
| 32 | + docker build --no-cache -f Dockerfile ./blog --tag ${{ env.IMAGE_BASE }}/${{ env.IMAGE_REPO }}-main:${{ steps.gen-tag.outputs.tag }} |
| 33 | + - name: Push the Docker image |
| 34 | + timeout-minutes: 3 |
| 35 | + run: | |
| 36 | + echo "Logging into Docker registry: ${{ env.IMAGE_BASE }}" |
| 37 | + docker login --username ${{ secrets.DOCKER_USERNAME }} --password ${{ secrets.DOCKER_PASSWORD }} ${{ env.IMAGE_BASE }} |
| 38 | + |
| 39 | + echo "Pushing Website Docker image with tag: ${{ steps.gen-tag.outputs.tag }}" |
| 40 | + docker push ${{ env.IMAGE_BASE }}/${{ env.IMAGE_REPO }}-main:${{ steps.gen-tag.outputs.tag }} |
| 41 | + |
| 42 | + - name: Checkout ArgoCD |
| 43 | + uses: actions/checkout@v4 |
| 44 | + with: |
| 45 | + repository: vidar-team-devops/argocd |
| 46 | + ssh-key: ${{ secrets.ARGO_KEY_SSH }} |
| 47 | + path: deploy |
| 48 | + |
| 49 | +# - name: Update ArgoCD |
| 50 | +# run: | |
| 51 | +# cd deploy/tutu |
| 52 | +# git config user.name github-actions |
| 53 | +# git config user.email [email protected] |
| 54 | +# sed -i "s|^\(\s*image:\s*.*:\)[0-9]\+|\1${{ steps.gen-tag.outputs.tag }}|" ./tutu/tutu-deployment.yml |
| 55 | +# sed -i "s|^\(\s*image:\s*.*:\)[0-9]\+|\1${{ steps.gen-tag.outputs.tag }}|" ./rsa-web-api/rsa-web-api-deployment.yml |
| 56 | +# sed -i "s|^\(\s*image:\s*.*:\)[0-9]\+|\1${{ steps.gen-tag.outputs.tag }}|" ./blog-mysql/blog-mysql-deployment.yml |
| 57 | +# git add . |
| 58 | +# git commit -m "update: image" |
| 59 | +# git push |
| 60 | + |
0 commit comments