Skip to content

Commit 2d7d178

Browse files
committed
Add comments to describe build and deploy
1 parent 57c134e commit 2d7d178

13 files changed

+120
-5
lines changed

.semaphore/client-deploy-build.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,16 @@ blocks:
5151
commands:
5252
- cd src/client
5353

54+
# Copy production configs we linked using secrets
5455
- cp /home/semaphore/client-production.env .env
5556

5657
# Restore dependencies from cache.
5758
# For more info on caching, see https://docs.semaphoreci.com/article/68-caching-dependencies
5859
- cache restore client-node-modules-$SEMAPHORE_GIT_BRANCH-$(checksum package-lock.json),client-node-modules-$SEMAPHORE_GIT_BRANCH,client-node-modules-master
5960

6061
- npm run build
61-
# Store the latest version of node modules in cache to reuse in
62-
# further blocks:
62+
63+
# Store the latest version of client build in cache to reuse in further blocks:
6364
- cache store client-build-$SEMAPHORE_WORKFLOW_ID build
6465

6566
# The deployment pipeline is defined to run on manual approval from the UI.

.semaphore/client-deploy.yml

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ blocks:
3232
# Restore build from cache.
3333
- cache restore client-build-$SEMAPHORE_WORKFLOW_ID
3434

35+
# Config ssh and git to push new build files into gh-pages branch of app repository
3536
- ssh-keyscan -H github.com >> ~/.ssh/known_hosts
3637
- chmod 600 ~/.ssh/id_rsa_semaphoreci_ghpages_deploy
3738
- ssh-add ~/.ssh/id_rsa_semaphoreci_ghpages_deploy
@@ -41,4 +42,5 @@ blocks:
4142

4243
- npm run deploy
4344

45+
# Restore change to global git repository url rewrite to previous value
4446
- git config --global url."https://github.com/".insteadOf "[email protected]:"
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
# Copy this file into one without .sample part and then populate it with actual values.
2+
# Then you can create secret, by using command
3+
# `sem create -f path/to/this/file`
4+
# More info https://docs.semaphoreci.com/article/66-environment-variables-and-secrets
15
apiVersion: v1alpha
26
kind: Secret
37
metadata:
8+
# Use this name to create this secret manually
49
name: client-production-env-secret
510
data:
611
files:
12+
# Client production.env file doesn't exist by default, copy src/client/sample.env into src/client/production.env
13+
# and populate with production values
14+
# Then create secret - in the end it should be here - https://<put-your-namespace-here>.semaphoreci.com/secrets
715
- path: client-production.env
8-
content: PASTE_BASE64_ENCODED_CONTENT_HERE
16+
# Could be created by
17+
# - `base64 -w 0 /path/to/file` and put in
18+
# - upload in https://<your-namesace>.semaphoreci.com/secrets
19+
content: PASTE_BASE64_ENCODED_CONTENT_HERE
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
1+
# Copy this file into one without .sample part and then populate it with actual values.
2+
# Then you can create secret, by using command
3+
# `sem create -f path/to/this/file`
4+
# More info https://docs.semaphoreci.com/article/66-environment-variables-and-secrets
15
apiVersion: v1alpha
26
kind: Secret
37
metadata:
8+
# Use this name to create this secret manually
49
name: gc-k8s-secret
510
data:
611
files:
12+
# If you haven't set up k8s on google you need to do it first
13+
# Start with https://cloud.google.com/kubernetes-engine/docs/quickstart
14+
# Play with it and then you can use it with this project.
15+
# Also check out https://docs.semaphoreci.com/article/119-ci-cd-for-microservices-on-kubernetes
16+
# as example of k8s deploy.
17+
# If you have admin of dev ops - contact them to obtain this config
18+
# Also you could try to get this yourself in case you have permissions
19+
# Run command
20+
# `gcloud container clusters get-credentials [CLUSTER_NAME]`
21+
# Then look for `.kube` folder and find config.yaml there.
722
- path: .kube/gc-k8s.yaml
23+
# Could be created by
24+
# - `base64 -w 0 /path/to/file` and put in
25+
# - upload in https://<your-namesace>.semaphoreci.com/secrets
826
content: PASTE_BASE64_ENCODED_CONTENT_HERE
+20
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
1+
# Copy this file into one without .sample part and then populate it with actual values.
2+
# Then you can create secret, by using command
3+
# `sem create -f path/to/this/file`
4+
# More info https://docs.semaphoreci.com/article/66-environment-variables-and-secrets
15
apiVersion: v1alpha
26
kind: Secret
37
metadata:
8+
# Use this name to create this secret manually
49
name: gcr-secret
510
data:
11+
# If you haven't set up k8s on google you need to do it first
12+
# Start with https://cloud.google.com/kubernetes-engine/docs/quickstart
13+
# Play with it and then you can use it with this project.
14+
# Check out https://docs.semaphoreci.com/article/72-google-container-registry-gcr as an example.
15+
# Also check out https://docs.semaphoreci.com/article/119-ci-cd-for-microservices-on-kubernetes
16+
# as example of k8s deploy.
617
env_vars:
18+
# Id of your project
19+
# More info here https://cloud.google.com/resource-manager/docs/creating-managing-projects?visit_id=636878590586351739-3388570778&rd=1#identifying_projects
720
- name: GCP_PROJECT_ID
821
value: "your-gcp-project-id"
22+
# Default compute zone you've selected
23+
# https://cloud.google.com/compute/docs/regions-zones/#available
924
- name: GCP_PROJECT_DEFAULT_ZONE
1025
value: "europe-west1-b"
1126
files:
27+
# You need to create service account and export json key file for it here https://console.cloud.google.com/iam-admin/serviceaccounts
28+
# to use in this file.
1229
- path: .secrets.gcp.json
30+
# Could be created by
31+
# - `base64 -w 0 /path/to/file` and put in
32+
# - upload in https://<your-namesace>.semaphoreci.com/secrets
1333
content: PASTE_BASE64_ENCODED_CONTENT_HERE
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1+
# Copy this file into one without .sample part and then populate it with actual values.
2+
# Then you can create secret, by using command
3+
# `sem create -f path/to/this/file`
4+
# More info https://docs.semaphoreci.com/article/66-environment-variables-and-secrets
15
apiVersion: v1beta
26
kind: Secret
37
metadata:
8+
# Use this name to create this secret manually
49
name: gh-pages-secret
510
data:
611
env_vars:
12+
# Username of github user used for deploy
713
- name: GH_USERNAME
814
value: "super secret github username"
15+
# Email of github user used for deploy
916
- name: GH_EMAIL
1017
value: "super secret github email"
1118
files:
19+
# Generate ssh key https://help.github.com/en/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
20+
# Add it to account you will use to deploy to github here https://github.com/settings/keys
1221
- path: .ssh/id_rsa_semaphoreci_ghpages_deploy
22+
# Could be created by
23+
# - `base64 -w 0 /path/to/file` and put in
24+
# - upload in https://<your-namesace>.semaphoreci.com/secrets
1325
content: PASTE_BASE64_ENCODED_CONTENT_HERE
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1+
# Copy this file into one without .sample part and then populate it with actual values.
2+
# Then you can create secret, by using command
3+
# `sem create -f path/to/this/file`
4+
# More info https://docs.semaphoreci.com/article/66-environment-variables-and-secrets
15
apiVersion: v1beta
26
kind: Secret
37
metadata:
8+
# Use this name to create this secret manually
49
name: server-ormconfig-production
510
data:
611
files:
12+
# Copy src/server/ormconfig.sample.json into ormconfig.production.json and populate with production values
13+
# You will need production connection settings in this config file.
14+
# In this eample heroku postgres database addon is used.
15+
# You will need to create heroku app and then add addon https://elements.heroku.com/addons/heroku-postgresql
16+
# Then you will be able to view database connection settings like described here https://devcenter.heroku.com/articles/heroku-postgresql#external-connections-ingress
717
- path: ormconfig.production.json
18+
# Could be created by
19+
# - `base64 -w 0 /path/to/file` and put in
20+
# - upload in https://<your-namesace>.semaphoreci.com/secrets
821
content: PASTE_BASE64_ENCODED_CONTENT_HERE
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
# Copy this file into one without .sample part and then populate it with actual values.
2+
# Then you can create secret, by using command
3+
# `sem create -f path/to/this/file`
4+
# More info https://docs.semaphoreci.com/article/66-environment-variables-and-secrets
15
apiVersion: v1beta
26
kind: Secret
37
metadata:
8+
# Use this name to create this secret manually
49
name: server-production-env
510
data:
611
files:
12+
# Server production.env file doesn't exist by default, copy src/server/sample.env into src/server/production.env
13+
# and populate with production values
14+
# Then create secret - in the end it should be here - https://<put-your-namespace-here>.semaphoreci.com/secrets
715
- path: server-production.env
8-
content: PASTE_BASE64_ENCODED_CONTENT_HERE
16+
# Could be created by
17+
# - `base64 -w 0 /path/to/file` and put in
18+
# - upload in https://<your-namesace>.semaphoreci.com/secrets
19+
content: PASTE_BASE64_ENCODED_CONTENT_HERE

.semaphore/server-docker-build.yml

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ blocks:
2020
- name: server-production-env
2121
prologue:
2222
commands:
23+
# Lets configure gcloud to push docker image into container registry
2324
# Authenticate using the file injected from the secret
2425
- gcloud auth activate-service-account --key-file=.secrets.gcp.json
2526
# Don't forget -q to silence confirmation prompts
@@ -32,6 +33,7 @@ blocks:
3233
commands:
3334
- cd src/server
3435

36+
# Copy production configs we linked using secrets
3537
- cp /home/semaphore/ormconfig.production.json ormconfig.json
3638
- cp /home/semaphore/server-production.env production.env
3739

README.md

+26-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ project](https://docs.semaphoreci.com/article/63-your-first-project).
1111

1212
The CI pipeline will look like this:
1313

14-
![CI pipeline on Semaphore](images/ci-pipeline.png)
14+
![CI pipeline on Semaphore](images/ci-pipeline-client.png)
15+
16+
![CI pipeline on Semaphore](images/ci-pipeline-server.png)
1517

1618
The example pipeline contains 4 blocks:
1719

@@ -25,6 +27,23 @@ The example pipeline contains 4 blocks:
2527
- Runs E2E tests through cypress on client.
2628
- Runs E2E tests through jest on server.
2729

30+
Then, if all checks are ok, we move to build pipeline. It consists of one block
31+
32+
- Build
33+
- Build client- build client app using create-react-app sctipts
34+
- Build server - build container and push it into google repository
35+
36+
Then, after we've built our apps we move to deploy pipeline.
37+
It also consists of one block for client and of two for server.
38+
As you can see deploy pipelines of client and server depend only on their own build step
39+
and therefore could be run in parallel.
40+
41+
- Deploy
42+
- Deploy client - commit and push build into gh-pages branch to deploy on Github
43+
- Deploy server
44+
- Deploy server to k8s, pdate k8s deployment using deployment config
45+
- Tag container if all went well
46+
2847
## Local project setup
2948

3049
This project requires a PostgreSQL database. If you don't have one you can
@@ -56,6 +75,12 @@ Steps described in server [README](src/server/README.md)
5675

5776
Steps described in client [README](src/client/README.md)
5877

78+
## Deploy configuration
79+
80+
Check out `.semaphore/` folder - steps described there have helpful comments to help you figure out what commands are doing.
81+
Also check out `.semaphore/secrets` folder. To configure deploy you need to create and populate all those secrets.
82+
Copy each secret file into file without `.sample` in filename and populate it. All of them have useful description comments to help you out.
83+
5984
## License
6085

6186
Copyright (c) 2019 Rendered Text

images/ci-pipeline-client.png

49.1 KB
Loading

images/ci-pipeline-server.png

53.6 KB
Loading

images/ci-pipeline.png

-71.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)