I've seen the concept of a "workspace" in multiple parts of the documentation and also in some answers to questions I've had on here. I can't find anywhere in the docs that defines what a workspace really is or how to define one.
At the moment I'm trying to break down my multi service copilot project to use multiple workspaces so that I can have separate build pipelines. Running the init commands in my subfolders don't do anything though, I still end up with the same top level copilot structure that defines them all together. (see #2256).
I have a .workspace file at the root of my application and I would expect there to be some way to break this up into multiple workspaces. Sorry for my noobiness.
If I'm reading this right, what you have is:
my-app/
โโ copilot/
โ โโ service1/
โ โ โโ manifest.yml
โ โโ service2/
| | โโ manifest.yml
| โโ .workspace
| โโ buildspec.yml
| โโ pipeline.yml
โโ service1/
โ โโ main.go
โ โโ Dockerfile
โโ service2/
โ โโ main.go
โ โโ Dockerfile
โโ.git/
Where what you want is:
my-app/
โโ service1/
| โโ copilot/
| โ โโ service1/
| โ โ โโ manifest.yml
| | โโ .workspace
| | โโ buildspec.yml
| | โโ pipeline.yml
โ โโ main.go
โ โโ Dockerfile
โโ service2/
| โโ copilot/
| โ โโ service2/
| โ โ โโ manifest.yml
| | โโ .workspace
| | โโ buildspec.yml
| | โโ pipeline.yml
โ โโ main.go
โ โโ Dockerfile
โโ .git/
Is that right?
If so, then you could do this by deleting your copilot directory at the top level, then doing the following:
cd service1
copilot app init -n myapp
copilot svc init -n service1 --dockerfile ./Dockerfile
cd ../service2
copilot app init -n myapp
copilot svc init -n service2 --dockerfile ./Dockerfile
should result in the correct directory structure. You'd have to be sure to run all copilot commands from inside of the service1 or service2 directories, though.
You'll also have to modify each pipeline's buildspec to move to the correct directory for each service so that docker can build the images correctly.
post_build:
commands:
- ls -l
- export COLOR="false"
# First, upgrade the cloudformation stack of every environment in the pipeline.
- pipeline=$(cat $CODEBUILD_SRC_DIR/copilot/pipeline.yml | ruby -ryaml -rjson -e 'puts JSON.pretty_generate(YAML.load(ARGF))')
- pl_envs=$(echo $pipeline | jq '.stages[].name' | sed 's/"//g')
# Add these two commands in the buildspec for each service
- mv ./copilot-linux service1/copilot-linux
- cd service1
- >
for pl_env in $pl_envs; do
./copilot-linux env upgrade -n $pl_env;
done;
...
Thanks, @bvtujo!
@mikelhamer, when you build your pipelines, be sure to change the pipeline names between pipeline init and pipeline update so they're different from each other.
Thank you both! Yes @bvtujo that is the set up I'm looking for. I will try this out and come back if I run into any issues.
I seriously appreciate how helpful everyone here is. Thanks a million!