From b917fd5b0c88a768038139a97441f992c81d40b7 Mon Sep 17 00:00:00 2001 From: mugioka Date: Sat, 30 Mar 2024 17:18:20 +0900 Subject: [PATCH 1/3] feat: build and push container image to GHCR. Signed-off-by: mugioka --- .github/workflows/{build.yml => ci.yml} | 24 +++++++------ .github/workflows/release.yaml | 45 +++++++++++++++++++++++++ Dockerfile | 4 +-- Dockerfile.local | 2 +- docker-compose.mongo-replica.yml | 4 +-- docker-compose.mxt-local.yml | 5 ++- go.mod | 2 +- 7 files changed, 65 insertions(+), 21 deletions(-) rename .github/workflows/{build.yml => ci.yml} (53%) create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/build.yml b/.github/workflows/ci.yml similarity index 53% rename from .github/workflows/build.yml rename to .github/workflows/ci.yml index db4464f..63dc3f7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/ci.yml @@ -1,26 +1,28 @@ -name: Build +name: CI on: + # NOTE: To comment SonarCloud coverage to GitHub Pull Request, we need to run the CI on pull requests. + pull_request: + types: [opened, synchronize, reopened] push: branches: - - '**' - pull_request: - types: [opened, reopened] - + - develop + - main jobs: - sonarcloud: - name: SonarCloud + test: + name: Test and upload coverage to SonarCloud runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v4.1.1 with: fetch-depth: 0 - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v5.0.0 with: - go-version: 1.17 + go-version: 1.22.1 - - name: Test + - name: Test with coverage run: go test --tags=test -coverprofile=cover.out $(go list ./... | grep -v mxtransporter/cmd) - name: SonarCloud Scan diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..cbe2a92 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,45 @@ +name: Release +on: + push: + tags: + - '[0-9]+.[0-9]+.[0-9]+' + - '[0-9]+.[0-9]+.[0-9]+-rc[0-9]+' +jobs: + publish-container-image: + name: Publish Container Image to GitHub Container Registry + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4.1.1 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3.0.0 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.2.0 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3.1.0 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Get metadata + id: get-metadata + uses: docker/metadata-action@v5.5.1 + with: + images: ghcr.io/${{ github.repository }} + flavor: | + latest=true + tags: | + type=ref event=push tag + + - name: Build and push + uses: docker/build-push-action@v5.3.0 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.get-metadata.outputs.tags }} diff --git a/Dockerfile b/Dockerfile index ba20844..c9272b0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ ## ## Build ## -FROM golang:latest as build +FROM golang:1.22.1-bookworm as build LABEL org.opencontainers.image.source="https://github.com/cam-inc/MxTransporter" @@ -24,7 +24,7 @@ RUN go install ./cmd/health.go ## ## Deploy ## -FROM alpine:latest +FROM alpine:3.19.1 WORKDIR /go/src diff --git a/Dockerfile.local b/Dockerfile.local index 73e4a90..127b205 100644 --- a/Dockerfile.local +++ b/Dockerfile.local @@ -1,4 +1,4 @@ -FROM golang:latest +FROM golang:1.22.1-bookworm WORKDIR /go/src diff --git a/docker-compose.mongo-replica.yml b/docker-compose.mongo-replica.yml index c18ca63..f5ee92a 100644 --- a/docker-compose.mongo-replica.yml +++ b/docker-compose.mongo-replica.yml @@ -1,7 +1,6 @@ version: '3.8' services: - mongodb-primary: image: mongo command: @@ -22,7 +21,7 @@ services: mongodb-secondary: image: mongo - command: + command: - --replSet - rs0 volumes: @@ -39,4 +38,3 @@ services: expose: - 27017 restart: always - diff --git a/docker-compose.mxt-local.yml b/docker-compose.mxt-local.yml index f984485..0bf70aa 100644 --- a/docker-compose.mxt-local.yml +++ b/docker-compose.mxt-local.yml @@ -1,7 +1,6 @@ version: '3.8' services: - mxt: build: context: '.' @@ -21,12 +20,12 @@ services: extends: file: docker-compose.mongo-replica.yml service: mongodb-primary - + mongodb-secondary: extends: file: docker-compose.mongo-replica.yml service: mongodb-secondary - + mongodb-arbiter: extends: file: docker-compose.mongo-replica.yml diff --git a/go.mod b/go.mod index 5f570d4..27fb4bc 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/cam-inc/mxtransporter -go 1.17 +go 1.22 require ( cloud.google.com/go/bigquery v1.18.0 From 46474ee6d32145aaa2cfcccaa1839c585948058c Mon Sep 17 00:00:00 2001 From: mugioka Date: Tue, 2 Apr 2024 15:05:41 +0900 Subject: [PATCH 2/3] fix: cannot publish container image. Signed-off-by: mugioka --- .github/workflows/release.yaml | 2 +- README.md | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index cbe2a92..01fb7c7 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -33,7 +33,7 @@ jobs: flavor: | latest=true tags: | - type=ref event=push tag + type=ref,event=tag - name: Build and push uses: docker/build-push-action@v5.3.0 diff --git a/README.md b/README.md index 629db0e..31e5b9d 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,9 @@ With MxTransporter, real-time data can be reproduced and retained on the data ut [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=cam-inc_MxTransporter&metric=coverage)](https://sonarcloud.io/summary/new_code?id=cam-inc_MxTransporter) +[![CI](https://github.com/cam-inc/MxTransporter/actions/workflows/ci.yml/badge.svg)](https://github.com/cam-inc/MxTransporter/actions/workflows/ci.yml) +[![Release](https://github.com/cam-inc/MxTransporter/actions/workflows/release.yaml/badge.svg)](https://github.com/cam-inc/MxTransporter/actions/workflows/release.yaml) +[![GitHub release](https://img.shields.io/github/release/cam-inc/MxTransporter.svg?style=flat-square)](https://github.com/cam-inc/MxTransporter/releases/latest)
# Features @@ -269,8 +272,8 @@ It is basic JSON. It is possible to change the key of ChangeStream, add a Time f
# Contributors -| [
Kenshirou](https://github.com/KenFujimoto12)
| [
Yoshinori Sugiyama](https://github.com/syama666)
| -| :---: | :---: | +| [
Kenshirou](https://github.com/KenFujimoto12)
| [
Yoshinori Sugiyama](https://github.com/syama666)
| +| :---------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------: |
From 4b4a910dac6637354db43d6ccc6af08cbfb26d2f Mon Sep 17 00:00:00 2001 From: mugioka Date: Tue, 9 Apr 2024 08:51:17 +0900 Subject: [PATCH 3/3] chore: update docs. --- README.md | 2 ++ README_JP.md | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 31e5b9d..d7e659d 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ MxTransporter is a middleware that accurately carries change streams of MongoDB in real time. For infrastructure, you can easily use this middleware by creating a container image with Dockerfile on any platform and deploying it. +It is also possible to download and use container image without having to build them, as they are published on the [GitHub Container Registry](https://github.com/cam-inc/MxTransporter/pkgs/container/mxtransporter). + With MxTransporter, real-time data can be reproduced and retained on the data utilization side, and data utilization will become even more active. :jp: Japanese version of the README is [here](/README_JP.md). diff --git a/README_JP.md b/README_JP.md index 7eb26d8..2005cc1 100644 --- a/README_JP.md +++ b/README_JP.md @@ -2,6 +2,8 @@ MxTransporter は MongoDB の Change Streams を正確に、リアルタイムで送信先に運ぶミドルウェアです。MxTransporter は、用意された Dockerfile からコンテナイメージを作成し、お好きな環境へデプロイすることで簡単に利用することができます。 +また、[GitHub Container Registry](https://github.com/cam-inc/MxTransporter/pkgs/container/mxtransporter) 上にコンテナイメージを公開しているため、ビルドすることなく、コンテナイメージを取得して利用することも可能です。 + MxTransporterにより、データ活用側でリアルタイムなデータを再現、保持でき、データ活用がより一層活発になるでしょう。 [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE) @@ -268,8 +270,8 @@ Change Streams をエクスポート先に送る前にフォーマットを整
# Contributors -| [
Kenshirou](https://github.com/KenFujimoto12)
| [
Yoshinori Sugiyama](https://github.com/syama666)
| -| :---: | :---: | +| [
Kenshirou](https://github.com/KenFujimoto12)
| [
Yoshinori Sugiyama](https://github.com/syama666)
| +| :---------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------: |