diff --git a/.github/workflows/odh-v2-core-writer.yaml b/.github/workflows/odh-v2-core-writer.yaml new file mode 100644 index 0000000..f932531 --- /dev/null +++ b/.github/workflows/odh-v2-core-writer.yaml @@ -0,0 +1,58 @@ +name: CI/CD odh-v2-core-writer + +on: + push: + paths: + - "infrastructure/raw-writer/**" + - "infrastructure/helm/raw-writer/**" + - ".github/workflows/odh-v2-core-writer.yaml" + workflow_dispatch: + +env: + WORKING_DIRECTORY: infrastructure/raw-writer + KUBERNETES_NAMESPACE: core + KUBERNETES_VALUE_PATH: infrastructure/helm/raw-writer/values.yaml + KUBERNETES_CHART_PATH: infrastructure/helm/raw-writer/raw-writer + PROJECT_NAME: raw-writer + +jobs: + build: + if: github.ref == 'refs/heads/refactor/noti-router' || github.ref == 'refs/heads/prod' + runs-on: ubuntu-22.04 + concurrency: odh-v2-core-writer-build + steps: + - name: Checkout source code + uses: actions/checkout@v4 + + - name: Log in to GitHub Docker Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Manually build and push image + run: cd ${{ env.WORKING_DIRECTORY }} && ./build.sh + + deploy: + if: github.ref == 'refs/heads/refactor/noti-router' || github.ref == 'refs/heads/prod' + needs: + - build + runs-on: ubuntu-22.04 + concurrency: odh-v2-core-writer-build-deploy + environment: ${{ github.ref == 'refs/heads/refactor/noti-router' && 'test' || github.ref == 'refs/heads/prod' && 'prod' || 'unknown' }} + steps: + - name: Checkout source code + uses: actions/checkout@v4 + + - name: Deploy on cluster + uses: noi-techpark/github-actions/helm-deploy@v2 + with: + k8s-name: ${{ env.PROJECT_NAME }} + k8s-namespace: ${{ env.KUBERNETES_NAMESPACE }} + chart-path: ${{ env.KUBERNETES_CHART_PATH }} + values-file: ${{ env.KUBERNETES_VALUE_PATH }} + aws-access-key-id: ${{ secrets[vars.AWS_KEY_ID] }} + aws-secret-access-key: ${{ secrets[vars.AWS_KEY_SECRET] }} + aws-eks-cluster-name: aws-main-eu-01 + aws-region: eu-west-1 \ No newline at end of file diff --git a/infrastructure/helm/raw-writer/raw-writer/values.yaml b/infrastructure/helm/raw-writer/raw-writer/values.yaml index 22a8846..abe8be8 100644 --- a/infrastructure/helm/raw-writer/raw-writer/values.yaml +++ b/infrastructure/helm/raw-writer/raw-writer/values.yaml @@ -20,6 +20,8 @@ env: value: ingress - name: APP_MQ_QUEUE value: ingress + - name: APP_MQ_READY_EXCHANGE + value: ready - name: APP_LOGLEVEL value: INFO diff --git a/infrastructure/helm/raw-writer/values.yaml b/infrastructure/helm/raw-writer/values.yaml index e0d0c76..1528fab 100644 --- a/infrastructure/helm/raw-writer/values.yaml +++ b/infrastructure/helm/raw-writer/values.yaml @@ -13,6 +13,8 @@ env: value: ingress - name: APP_MQ_QUEUE value: ingress + - name: APP_MQ_READY_EXCHANGE + value: ready - name: APP_MONGO_URI valueFrom: secretKeyRef: diff --git a/infrastructure/raw-writer/.env.example b/infrastructure/raw-writer/.env.example index 9a2a3c1..4c16f8d 100644 --- a/infrastructure/raw-writer/.env.example +++ b/infrastructure/raw-writer/.env.example @@ -1,7 +1,7 @@ APP_MQ_URI=amqp://guest:guest@rabbitmq:5672 +APP_MQ_EXCHANGE=ingress +APP_MQ_QUEUE=ingress APP_MQ_READY_EXCHANGE=ready -APP_MQ_READY_QUEUE=ready -APP_MQ_ROUTED_EXCHANGE=routed -APP_MQ_ROUTED_QUEUE=routed +APP_MONGO_URI=mongodb://mongodb APP_LOGLEVEL=DEBUG \ No newline at end of file diff --git a/infrastructure/raw-writer/main.go b/infrastructure/raw-writer/main.go index 8890e88..d807f79 100644 --- a/infrastructure/raw-writer/main.go +++ b/infrastructure/raw-writer/main.go @@ -24,12 +24,13 @@ import ( ) var cfg struct { - MQ_URI string - MQ_Exchange string - MQ_QUEUE string - LogLevel string `default:"INFO"` - MONGO_URI string - DB_PREFIX string + MQ_URI string + MQ_Exchange string + MQ_QUEUE string + MQ_READY_EXCHANGE string + LogLevel string `default:"INFO"` + MONGO_URI string + DB_PREFIX string } type mqErr struct { @@ -96,6 +97,8 @@ func setupMQ() <-chan *message.Message { } func setupReadyPublisher() *amqp.Publisher { + // setup only open a connection with rabbitmq and tells publisher that + // exchange needs to be "direct". Exchange creation is delegated to message publish amqpConfig := amqp.NewDurablePubSubConfig(cfg.MQ_URI, amqp.GenerateQueueNameConstant("")) amqpConfig.Exchange.Durable = true amqpConfig.Exchange.AutoDeleted = false @@ -173,7 +176,7 @@ func handleMqMsg(msg *message.Message) *mqErr { return nil, err } msg := message.NewMessage(watermill.NewUUID(), messagePayload) - return nil, readyPublisher.Publish("ready", msg) + return nil, readyPublisher.Publish(cfg.MQ_READY_EXCHANGE, msg) }, nil), )