Organizing multiple projects and branching

aws

#1

Hi,

if I have a bunch of serverless projects - each one for a different microserice, then whats the best way to organize them in git ?

I would like to have them all in a services folder in one git project, but this complicates things when I have dev/qa/master branches and for example would like my continuous build to deploy a new version of only one of the services

any suggestions ?


#2

I have discussed this with @buggy before with this ticket

you can take a reference.

way #1, manage the custom variables for all environments in one place (@buggy’s way)

way #2, manage custom variable files for each environment (my way.)

You needn’t manage the branches for different environments, you can put them in master branch directly.


#3

I was more talking about how to lay out the various serverless projects. If I put all the projects inside one git project then a change to any one of them could cause the whole build process to re-deploy all microservices each time. Just looking for best advice really on how to structure them so that they can still share config but still build/deploy independently, can codepipeline help with any of this?


#4

It sounds like you’re talking about a monorepo. Try googling deploy monorepo independently as the problem you’re trying to solve “which apps inside the monorepo need redeploying after a commit” isn’t a problem specific to Serverless. The solution for other platforms could be applied to Serverless too.


#5

If they are totally different projects, why not manage in different repositories?

if you want to manage similar projects, then you can define the custom variables to re-use the codes.


#6

thanks guys, just trying to keep things easy to manage and keep track of for the moment.
I think I’ll just put everything in one repo for the moment and eventually move things out as things take shape. I guess for now I can always add some sort of script with git commands to check for folders that changed and then build/deploy only certain projects accordingly


#7

Serverless keeps cache of deployed service in .serverless folder, so it won’t redeploy it if nothing is changed.
If you’re using circleci or similar, you can keep .serverless directories as an artifacts to speed up the process.
We recently open-sourced tool that we’re using internaly https://github.com/8bites/serviceless to deploy multiple services in parallel.


#8

ah great, good to know


#9

@pvlasov don’t suppose you have an example circleci/other serverless monorep config where .serverless folder is retained ?


#10

have been trying bitbuck pipelines, but cannot get caches to work…

+ /usr/local/lib/node_modules/serverless/bin/serverless deploy
bash: /usr/local/lib/node_modules/serverless/bin/serverless: No such file or directory





# This is a sample build configuration for JavaScript.
# Check our guides at https://confluence.atlassian.com/x/14UWN for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: node:6.9.4

pipelines:
  default:
    - step:
        caches:
          - global-node
          
        script: # Modify the commands below to build your repository.
          - ls /usr/local/lib/node_modules
          - npm install serverless -g
          - npm install serviceless -g
          - serverless config credentials --provider aws --key $aws_secret_access_key --secret $aws_access_key_id
          
         

    - parallel:
        - step:
            name: service-one..
            caches:
              - service-one-node
              - service-one-serverless
            script:
              - cd ./backend/services/service-one
              - npm install
              - npm test
              - /usr/local/lib/node_modules/serverless/bin/serverless deploy
        - step:
            name: service-two..
            caches:
              - service-two-node
              - service-two-serverless
            script:
              - cd ./backend/services/service-two
              - npm install
              - npm test
              - /usr/local/lib/node_modules/serverless/bin/serverless deploy

    - step:          
        script: 
          - echo "we would deploy all here if all tests succeeded"    


definitions:
  caches:
    global-node: /usr/local/lib/node_modules
    service-one-node: ./backend/services/service-one/node_modules
    service-one-serverless: ./backend/services/service-one/.serverless
    service-two-node: ./backend/services/service-two/node_modules
    service-two-serverless: ./backend/services/service-two/.serverless

#11

try to run from a serverless docker image? which will be suitable for pipeline.


#12

that only complicates things further, want to stay away from docker


#13

Hey @walshe I ended up writing a chapter on this over at Serverless Stack.