From b9df5588acdaa26a68a89286f76512c9e98f1a61 Mon Sep 17 00:00:00 2001 From: SammyOina Date: Wed, 20 Dec 2023 16:27:23 +0300 Subject: [PATCH 1/3] Create and publish a Docker image This commit adds a new file `.github/workflows/build.yml` which contains the workflow configuration for creating and publishing a Docker image. The workflow is triggered on push events to the `main` branch. It sets environment variables for the registry and image name. The job runs on `ubuntu-latest` and has necessary permissions for reading contents and writing packages. The steps include checking out the repository, logging in to the container registry using the GitHub token, and extracting metadata for Docker. Signed-off-by: SammyOina --- .github/workflows/build.yml | 48 +++++++++++++++++++++++++++++++++++++ Makefile | 4 ++-- docker/docker-compose.yml | 2 +- 3 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..d5ca70f1 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,48 @@ +# Copyright (c) Ultraviolet +# SPDX-License-Identifier: Apache-2.0 + +name: Create and publish a Docker image + +on: + push: + branches: ["main"] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build API Gateway and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./docker/Dockerfile + push: true + build-args: | + SVC=manager + tags: ghcr.io/ultravioletrs/cocos/manager:latest + labels: ${{ steps.meta.outputs.labels }} diff --git a/Makefile b/Makefile index 82668d7f..ba7db29d 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ define make_docker --build-arg VERSION=$(VERSION) \ --build-arg COMMIT=$(COMMIT) \ --build-arg TIME=$(TIME) \ - --tag=cocos-ai/$(svc) \ + --tag=ghcr.io/ultravioletrs/cocos/$(svc) \ -f docker/Dockerfile . endef @@ -45,7 +45,7 @@ define make_docker_dev docker build \ --no-cache \ --build-arg SVC=$(svc) \ - --tag=cocos-ai/$(svc) \ + --tag=ghcr.io/ultravioletrs/cocos/$(svc) \ -f docker/Dockerfile.dev ./build endef diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 709cd406..c750779d 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -24,7 +24,7 @@ services: networks: - cocos-base-net cocos-manager: - image: cocos-ai/manager:latest + image: ghcr.io/ultravioletrs/cocos/manager:latest container_name: cocos-manager env_file: - .env From 6a7eb39df17f1221b063a7a44d3362108e53cfbb Mon Sep 17 00:00:00 2001 From: SammyOina Date: Thu, 21 Dec 2023 18:39:13 +0300 Subject: [PATCH 2/3] Refactor build workflow and update Makefile The build workflow has been refactored to build the Manager image instead of the API Gateway image. The Makefile has also been updated. The changes include: - Renaming the build step to "Build Manager and push Docker image" - Updating the image name to include "/manager" - Updating the build arguments to use "SVC=manager" - Updating the tags to use the output from the metadata action These changes ensure that the correct Docker image is built and pushed. Signed-off-by: SammyOina --- .github/workflows/build.yml | 6 +++--- Makefile | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d5ca70f1..de4ecb77 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,9 +34,9 @@ jobs: id: meta uses: docker/metadata-action@v5 with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/manager - - name: Build API Gateway and push Docker image + - name: Build Manager and push Docker image uses: docker/build-push-action@v5 with: context: . @@ -44,5 +44,5 @@ jobs: push: true build-args: | SVC=manager - tags: ghcr.io/ultravioletrs/cocos/manager:latest + tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/Makefile b/Makefile index ba7db29d..d1707c21 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,7 @@ CLI_SOURCE = ./cmd/cli/main.go CLI_BIN = ${BUILD_DIR}/cocos-cli DOCKERS = $(addprefix docker_,$(SERVICES)) DOCKERS_DEV = $(addprefix docker_dev_,$(SERVICES)) +COCOS_DOCKER_IMAGE_NAME_PREFIX=ghcr.io/ultravioletrs/cocos/ USER_REPO ?= $(shell git remote get-url origin | sed -e 's/.*\/\([^/]*\)\/\([^/]*\).*/\1_\2/' ) empty:= @@ -35,7 +36,7 @@ define make_docker --build-arg VERSION=$(VERSION) \ --build-arg COMMIT=$(COMMIT) \ --build-arg TIME=$(TIME) \ - --tag=ghcr.io/ultravioletrs/cocos/$(svc) \ + --tag=$(COCOS_DOCKER_IMAGE_NAME_PREFIX)$(svc) \ -f docker/Dockerfile . endef @@ -45,7 +46,7 @@ define make_docker_dev docker build \ --no-cache \ --build-arg SVC=$(svc) \ - --tag=ghcr.io/ultravioletrs/cocos/$(svc) \ + --tag=$(COCOS_DOCKER_IMAGE_NAME_PREFIX)$(svc) \ -f docker/Dockerfile.dev ./build endef From 094dc982b93caf6b6643a124fdcfb8ced82d49fb Mon Sep 17 00:00:00 2001 From: SammyOina Date: Thu, 21 Dec 2023 19:25:54 +0300 Subject: [PATCH 3/3] remove labels Signed-off-by: SammyOina --- .github/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index de4ecb77..991d9cfb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -45,4 +45,3 @@ jobs: build-args: | SVC=manager tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }}