From f1784ce6fdbac0ab4357a7732d9689c9ebdaca3a Mon Sep 17 00:00:00 2001 From: Sam Yuan Date: Fri, 1 Dec 2023 21:13:17 +0800 Subject: [PATCH] enhance CI for build image logic Signed-off-by: Sam Yuan --- .github/workflows/build-push.yml | 62 +++++++++++++++---------- .github/workflows/docker-base-image.yml | 38 --------------- Makefile | 4 +- 3 files changed, 40 insertions(+), 64 deletions(-) delete mode 100644 .github/workflows/docker-base-image.yml diff --git a/.github/workflows/build-push.yml b/.github/workflows/build-push.yml index ff10ca7b..6ae521cc 100644 --- a/.github/workflows/build-push.yml +++ b/.github/workflows/build-push.yml @@ -2,42 +2,56 @@ name: BuildPushDeployImage on: push: - -env: - IMAGE_VERSION: '0.7' - IMAGE_REGISTRY: quay.io/sustainable_computing_io - IMAGE_NAME: kepler_model_server + branches: [ main ] jobs: - build: + buildbase: runs-on: ubuntu-latest - steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: set up QEMU - uses: docker/setup-qemu-action@v2 + uses: docker/setup-qemu-action@v3 - name: set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - name: build Kepler model server - run: make build - + uses: docker/setup-buildx-action@v3 - name: Login to Quay if: ${{ (github.repository_owner == 'sustainable-computing-io') && (github.ref == 'refs/heads/main') }} - uses: docker/login-action@v1 + uses: docker/login-action@v3 with: registry: quay.io/sustainable_computing_io username: ${{ secrets.BOT_NAME }} password: ${{ secrets.BOT_TOKEN }} + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64,linux/s390x + push: true + tags: quay.io/sustainable_computing_io/kepler_model_server_base:v0.7 + file: dockerfiles/Dockerfile.base - - name: Push to quay - if: ${{ (github.repository_owner == 'sustainable-computing-io') && (github.ref == 'refs/heads/main') }} - run: make push - - - - name: Tag latest and push to quay + build: + needs: [buildbase] + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4 + - name: set up QEMU + uses: docker/setup-qemu-action@v3 + - name: set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to Quay if: ${{ (github.repository_owner == 'sustainable-computing-io') && (github.ref == 'refs/heads/main') }} - run: | - docker tag ${{env.IMAGE_REGISTRY}}/${{env.IMAGE_NAME}}:v${{env.IMAGE_VERSION}} ${{env.IMAGE_REGISTRY}}/${{env.IMAGE_NAME}}:latest - docker push ${{env.IMAGE_REGISTRY}}/${{env.IMAGE_NAME}}:v${{env.IMAGE_VERSION}} - docker push ${{env.IMAGE_REGISTRY}}/${{env.IMAGE_NAME}}:latest \ No newline at end of file + uses: docker/login-action@v3 + with: + registry: quay.io/sustainable_computing_io + username: ${{ secrets.BOT_NAME }} + password: ${{ secrets.BOT_TOKEN }} + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64,linux/s390x + push: true + tags: quay.io/sustainable_computing_io/kepler_model_server:latest,quay.io/sustainable_computing_io/kepler_model_server:v0.7 + file: dockerfiles/Dockerfile diff --git a/.github/workflows/docker-base-image.yml b/.github/workflows/docker-base-image.yml deleted file mode 100644 index feafba62..00000000 --- a/.github/workflows/docker-base-image.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: Build and push base image - -on: - push: - branches: - - main - paths: - - dockerfiles/requirements.txt - - dockerfiles/Dockerfile.base - - .github/workflows/docker-base-image.yml - -env: - IMAGE_VERSION: '0.7' - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Build image - run: | - docker build -t quay.io/sustainable_computing_io/kepler_model_server_base:v${{env.IMAGE_VERSION}} dockerfiles -f dockerfiles/Dockerfile.base - - - name: Login to Quay - if: ${{ (github.repository_owner == 'sustainable-computing-io') && (github.ref == 'refs/heads/main') }} - uses: docker/login-action@v1 - with: - registry: quay.io/sustainable_computing_io - username: ${{ secrets.BOT_NAME }} - password: ${{ secrets.BOT_TOKEN }} - - - name: Push to quay - if: ${{ (github.repository_owner == 'sustainable-computing-io') && (github.ref == 'refs/heads/main') }} - run: | - docker push quay.io/sustainable_computing_io/kepler_model_server_base:v${{env.IMAGE_VERSION}} diff --git a/Makefile b/Makefile index 28383150..f1c64d3b 100644 --- a/Makefile +++ b/Makefile @@ -11,10 +11,10 @@ CTR_CMD = docker DOCKERFILES_PATH := "./dockerfiles" build: - $(CTR_CMD) build --platform linux/amd64 -t $(IMAGE) -f $(DOCKERFILES_PATH)/Dockerfile . + $(CTR_CMD) build -t $(IMAGE) -f $(DOCKERFILES_PATH)/Dockerfile . build-test: - $(CTR_CMD) build --platform linux/amd64 -t $(TEST_IMAGE) -f $(DOCKERFILES_PATH)/Dockerfile.test . + $(CTR_CMD) build -t $(TEST_IMAGE) -f $(DOCKERFILES_PATH)/Dockerfile.test . push: $(CTR_CMD) push $(IMAGE)