简体   繁体   中英

Deploy individual services from a monorepo using github actions

I have around 10 individual micro-services which are mostly cloud functions for various data processing jobs, which all live in a single github repository.

The goal is to trigger the selective deployment of these service to Google Cloud Functions, on push to a branch - when an individual function has been updated.

I must avoid the situation in which update of a single service causes the deployment of all the cloud functions.

My current repository structure:

/repo
--/service_A
----/function
----/notebook
--/service_B
----/function
----/notebook

On a side note, what are the pros/cons of using Github Actions VS Google Cloud Build for such automation?

GitHub Actions supports monorepos with path filtering for workflows. You can create a workflow to selectively trigger when files on a specific path change.

https://help.github.com/en/articles/workflow-syntax-for-github-actions#onpushpull_requestpaths

For example, this workflow will trigger on a push when any files under the path service_A/ have changed (note the ** glob to match files in nested directories).

on:
  push:
    paths:
      - 'service_A/**'

You could also run some script to discover which services were changed based on git diff and trigger corresponding job via GitHub REST API .

There could be two workflows main.yml and services.yml .

Main workflow will be configured to be started always on push and it will only start script to find out which services were changed. For each changed service repository dispatch event will be triggered with service name in payload.

Services workflow will be configured to be started on repository_dispatch and it will contain one job for each service. Jobs would have additional condition based on event payload.

See showcase with similar setup: https://github.com/zladovan/monorepo

Has Changed Path Action might be worth a try:

name: Conditional Deploy

on: push

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 100

      - uses: marceloprado/has-changed-path@v1
        id: service_A_deployment
        with:
          paths: service_A

      - name: Deploy front
        if: steps.service_A_deployment.outputs.changed == 'true'
        run: /deploy-service_A.sh

The answer is that you switch to using NX.dev and just let it work it out for you with its nx affected deploy command

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM