From 3d7041286bf53622e9ca52f862e982d5839459d6 Mon Sep 17 00:00:00 2001 From: Gaius Date: Tue, 25 Jan 2022 15:20:28 +0800 Subject: [PATCH] refactor: docker workflows (#1039) Signed-off-by: Gaius --- .github/workflows/docker.yml | 200 +++-------------------------------- 1 file changed, 12 insertions(+), 188 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 7efb02cf0..bf9f4fee7 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -2,13 +2,18 @@ name: Docker on: push: + branches: + - main tags: - v* jobs: - push_scheduler_to_registry: + push_image_to_registry: name: Push Scheduler Image runs-on: ubuntu-latest + strategy: + matrix: + module: ["manager", "scheduler", "cdn", "dfdaemon"] timeout-minutes: 10 steps: - name: Check out code @@ -20,7 +25,7 @@ jobs: id: get_version run: | VERSION=${GITHUB_REF#refs/tags/} - if [[ ${GITHUB_REF} == "refs/heads/master" ]]; then + if [[ ${GITHUB_REF} == "refs/heads/main" ]]; then VERSION=latest fi echo ::set-output name=VERSION::${VERSION} @@ -31,65 +36,9 @@ jobs: run: | echo "::set-output name=git_revision::$(git rev-parse --short HEAD)" - - name: Login Docker Hub - uses: docker/login-action@v1 - with: - registry: docker.io - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Login to GitHub Container Registry - uses: docker/login-action@v1 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: PrepareReg Names run: | - echo IMAGE_REPOSITORY=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV - echo IMAGE_TAG=$(echo ${{ github.ref }} | tr '[:upper:]' '[:lower:]' | awk '{split($0,a,"/"); print a[3]}') >> $GITHUB_ENV - - - name: Push to Docker Hub - uses: docker/build-push-action@v2 - with: - context: . - file: build/images/scheduler/Dockerfile - labels: |- - org.opencontainers.image.source=https://github.com/${{ github.repository }} - org.opencontainers.image.revision=${{ github.sha }} - build-args: | - GITVERSION=git-${{ steps.vars.outputs.git_revision }} - VERSION=${{ steps.get_version.outputs.VERSION }} - tags: | - dragonflyoss/scheduler:${{ steps.get_version.outputs.VERSION }} - ghcr.io/${{ env.IMAGE_REPOSITORY }}/scheduler:${{ steps.get_version.outputs.VERSION }} - push: true - - push_dfdaemon_to_registry: - name: Push Dfdaemon Image - runs-on: ubuntu-latest - timeout-minutes: 10 - steps: - - name: Check out code - uses: actions/checkout@v2 - with: - submodules: recursive - - - name: Get Version - id: get_version - run: | - VERSION=${GITHUB_REF#refs/tags/} - if [[ ${GITHUB_REF} == "refs/heads/master" ]]; then - VERSION=latest - fi - echo ::set-output name=VERSION::${VERSION} - - - name: Get Git Revision - id: vars - shell: bash - run: | - echo "::set-output name=git_revision::$(git rev-parse --short HEAD)" + echo IMAGE_REPOSITORY=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV - name: Login Docker Hub uses: docker/login-action@v1 @@ -105,136 +54,11 @@ jobs: username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - - name: PrepareReg Names - run: | - echo IMAGE_REPOSITORY=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV - echo IMAGE_TAG=$(echo ${{ github.ref }} | tr '[:upper:]' '[:lower:]' | awk '{split($0,a,"/"); print a[3]}') >> $GITHUB_ENV - - - name: Push to Docker Hub - uses: docker/build-push-action@v2 - with: - context: . - file: build/images/dfdaemon/Dockerfile - labels: |- - org.opencontainers.image.source=https://github.com/${{ github.repository }} - org.opencontainers.image.revision=${{ github.sha }} - build-args: | - GITVERSION=git-${{ steps.vars.outputs.git_revision }} - VERSION=${{ steps.get_version.outputs.VERSION }} - tags: | - dragonflyoss/dfdaemon:${{ steps.get_version.outputs.VERSION }} - ghcr.io/${{ env.IMAGE_REPOSITORY }}/dfdaemon:${{ steps.get_version.outputs.VERSION }} - push: true - - push_cdn_to_registry: - name: Push CDN Image - runs-on: ubuntu-latest - timeout-minutes: 10 - steps: - - name: Check out code - uses: actions/checkout@v2 - with: - submodules: recursive - - - name: Get Version - id: get_version - run: | - VERSION=${GITHUB_REF#refs/tags/} - if [[ ${GITHUB_REF} == "refs/heads/master" ]]; then - VERSION=latest - fi - echo ::set-output name=VERSION::${VERSION} - - - name: Get Git Revision - id: vars - shell: bash - run: | - echo "::set-output name=git_revision::$(git rev-parse --short HEAD)" - - - name: Login Docker Hub - uses: docker/login-action@v1 - with: - registry: docker.io - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Login to GitHub Container Registry - uses: docker/login-action@v1 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: PrepareReg Names - run: | - echo IMAGE_REPOSITORY=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV - echo IMAGE_TAG=$(echo ${{ github.ref }} | tr '[:upper:]' '[:lower:]' | awk '{split($0,a,"/"); print a[3]}') >> $GITHUB_ENV - - - name: Push to Docker Hub - uses: docker/build-push-action@v2 - with: - context: . - file: build/images/cdn/Dockerfile - labels: |- - org.opencontainers.image.source=https://github.com/${{ github.repository }} - org.opencontainers.image.revision=${{ github.sha }} - build-args: | - GITVERSION=git-${{ steps.vars.outputs.git_revision }} - VERSION=${{ steps.get_version.outputs.VERSION }} - tags: | - dragonflyoss/cdn:${{ steps.get_version.outputs.VERSION }} - ghcr.io/${{ env.IMAGE_REPOSITORY }}/cdn:${{ steps.get_version.outputs.VERSION }} - push: true - - push_manager_to_registry: - name: Push Manager Image - runs-on: ubuntu-latest - timeout-minutes: 10 - steps: - - name: Check out code - uses: actions/checkout@v2 - with: - submodules: recursive - - - name: Get Version - id: get_version - run: | - VERSION=${GITHUB_REF#refs/tags/} - if [[ ${GITHUB_REF} == "refs/heads/master" ]]; then - VERSION=latest - fi - echo ::set-output name=VERSION::${VERSION} - - - name: Get Git Revision - id: vars - shell: bash - run: | - echo "::set-output name=git_revision::$(git rev-parse --short HEAD)" - - - name: Login Docker Hub - uses: docker/login-action@v1 - with: - registry: docker.io - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Login to GitHub Container Registry - uses: docker/login-action@v1 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: PrepareReg Names - run: | - echo IMAGE_REPOSITORY=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV - echo IMAGE_TAG=$(echo ${{ github.ref }} | tr '[:upper:]' '[:lower:]' | awk '{split($0,a,"/"); print a[3]}') >> $GITHUB_ENV - - - name: Push to Docker Hub + - name: Push to Registry uses: docker/build-push-action@v2 with: context: . - file: build/images/manager/Dockerfile + file: build/images/${{ matrix.module }}/Dockerfile labels: |- org.opencontainers.image.source=https://github.com/${{ github.repository }} org.opencontainers.image.revision=${{ github.sha }} @@ -242,6 +66,6 @@ jobs: GITVERSION=git-${{ steps.vars.outputs.git_revision }} VERSION=${{ steps.get_version.outputs.VERSION }} tags: | - dragonflyoss/manager:${{ steps.get_version.outputs.VERSION }} - ghcr.io/${{ env.IMAGE_REPOSITORY }}/manager:${{ steps.get_version.outputs.VERSION }} + dragonflyoss/${{ matrix.module }}:${{ steps.get_version.outputs.VERSION }} + ghcr.io/${{ env.IMAGE_REPOSITORY }}/${{ matrix.module }}:${{ steps.get_version.outputs.VERSION }} push: true