Skip to content

Commit 5b22190

Browse files
committed
Add client deploy to gh pages
1 parent b609daf commit 5b22190

27 files changed

+650
-32
lines changed

.sample.env

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
POSTGRES_DB=demo
2-
POSTGRES_USER=demouser
3-
POSTGRES_PASSWORD=qwerty
1+
POSTGRES_DB=postgres
2+
POSTGRES_USER=postgres
3+
POSTGRES_PASSWORD=
4+
POSTGRES_PORT=5432

.semaphore/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*-secret.yml

.semaphore/client-deploy-build.yml

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Use the latest stable version of Semaphore 2.0 YML syntax:
2+
version: v1.0
3+
4+
# Name your pipeline. In case you connect multiple pipelines with promotions,
5+
# the name will help you differentiate between, for example, a CI build phase
6+
# and delivery phases.
7+
name: Semaphore JavaScript Example Pipeline
8+
9+
# An agent defines the environment in which your code runs.
10+
# It is a combination of one of available machine types and operating
11+
# system images.
12+
# See https://docs.semaphoreci.com/article/20-machine-types
13+
# and https://docs.semaphoreci.com/article/32-ubuntu-1804-image
14+
agent:
15+
machine:
16+
type: e1-standard-2
17+
os_image: ubuntu1804
18+
19+
# Blocks are the heart of a pipeline and are executed sequentially.
20+
# Each block has a task that defines one or more jobs. Jobs define the
21+
# commands to execute.
22+
# See https://docs.semaphoreci.com/article/62-concepts
23+
blocks:
24+
- name: Install dependencies
25+
task:
26+
# Set environment variables that your project requires.
27+
# See https://docs.semaphoreci.com/article/66-environment-variables-and-secrets
28+
env_vars:
29+
- name: NODE_ENV
30+
value: production
31+
- name: CI
32+
value: 'true'
33+
34+
# This block runs two jobs in parallel and they both share common
35+
# setup steps. We can group them in a prologue.
36+
# See https://docs.semaphoreci.com/article/50-pipeline-yaml#prologue
37+
prologue:
38+
commands:
39+
# Get the latest version of our source code from GitHub:
40+
- checkout
41+
42+
# Use the version of Node.js specified in .nvmrc.
43+
# Semaphore provides nvm preinstalled.
44+
- nvm use
45+
- node --version
46+
- npm --version
47+
jobs:
48+
# First parallel job:
49+
- name: client npm install and cache
50+
commands:
51+
- cd src/client
52+
53+
# Restore dependencies from cache.
54+
# For more info on caching, see https://docs.semaphoreci.com/article/68-caching-dependencies
55+
- cache restore client-node-modules-$SEMAPHORE_GIT_BRANCH-$(checksum package-lock.json),client-node-modules-$SEMAPHORE_GIT_BRANCH,client-node-modules-master
56+
57+
- npm run build
58+
# Store the latest version of node modules in cache to reuse in
59+
# further blocks:
60+
- cache store client-build-$SEMAPHORE_GIT_BRANCH-$(checksum package-lock.json) build
61+
62+
# The deployment pipeline is defined to run on manual approval from the UI.
63+
# Semaphore will the time and the name of the person who promotes each
64+
# deployment.
65+
#
66+
# You could, for example, add another promotion to a pipeline that
67+
# automatically deploys to a staging environment from branches named
68+
# after a certain pattern.
69+
# https://docs.semaphoreci.com/article/50-pipeline-yaml#promotions
70+
promotions:
71+
- name: Deploy Client
72+
pipeline_file: client-deploy.yml

.semaphore/client-deploy.yml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# This pipeline runs after semaphore.yml
2+
version: v1.0
3+
name: Client deploy
4+
agent:
5+
machine:
6+
# Use a machine type with more RAM and CPU power for faster container
7+
# builds:
8+
type: e1-standard-4
9+
os_image: ubuntu1804
10+
blocks:
11+
- name: Build
12+
task:
13+
# Mount a secret which defines DOCKER_USERNAME and DOCKER_PASSWORD
14+
# environment variables.
15+
# For info on creating secrets, see:
16+
# https://docs.semaphoreci.com/article/66-environment-variables-and-secrets
17+
secrets:
18+
- name: gh-pages-secret
19+
- name: gh-pages-ssh-key
20+
prologue:
21+
commands:
22+
# Get the latest version of our source code from GitHub:
23+
- checkout --use-cache
24+
jobs:
25+
- name: Deploy to GitHub Pages
26+
commands:
27+
- cd src/client
28+
29+
# Restore dependencies from cache.
30+
# For more info on caching, see https://docs.semaphoreci.com/article/68-caching-dependencies
31+
- cache restore client-node-modules-$SEMAPHORE_GIT_BRANCH-$(checksum package-lock.json),client-node-modules-$SEMAPHORE_GIT_BRANCH,client-node-modules-master
32+
33+
# Restore build from cache.
34+
- cache restore client-build-$SEMAPHORE_GIT_BRANCH-$(checksum package-lock.json) build
35+
36+
- ssh-keyscan -H github.com >> ~/.ssh/known_hosts
37+
- chmod 600 ~/.ssh/id_rsa_semaphoreci_ghpages_deploy
38+
- ssh-add ~/.ssh/id_rsa_semaphoreci_ghpages_deploy
39+
- git config --global url."[email protected]:".insteadOf "https://github.com/"
40+
- git config --global user.name '$GH_USERNAME'
41+
- git config --global user.email '$GH_EMAIL'
42+
43+
- npm run justdeploy
44+
45+
- git config --global url."https://github.com/".insteadOf "[email protected]:"

.semaphore/gc-k8s-secret.sample.yml

Whitespace-only changes.

.semaphore/gcr-secret.sample.yml

Whitespace-only changes.

.semaphore/gh-pages-secret.sample.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1beta
2+
kind: Secret
3+
metadata:
4+
name: gh-pages-secret
5+
data:
6+
env_vars:
7+
- name: GH_USERNAME
8+
value: "super secret github username"
9+
- name: GH_EMAIL
10+
value: "super secret github email"

.semaphore/semaphore.yml

+20
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,23 @@ blocks:
157157
- cp ormconfig.ci.json ormconfig.json
158158
- npm run migrate:up
159159
- npm run test:e2e
160+
161+
# If all tests pass, we move on to build a Docker image.
162+
# This is a job for a separate pipeline which we link with a promotion.
163+
#
164+
# What happens outside semaphore.yml will not appear in GitHub pull
165+
# request status report.
166+
#
167+
# In this example we run docker build automatically on every branch.
168+
# You may want to limit it by branch name, or trigger it manually.
169+
# For more on such options, see:
170+
# https://docs.semaphoreci.com/article/50-pipeline-yaml#promotions
171+
promotions:
172+
# - name: Dockerize server
173+
# pipeline_file: server-docker-build.yml
174+
# auto_promote_on:
175+
# - result: passed
176+
- name: Deploy client
177+
pipeline_file: client-deploy.yml
178+
auto_promote_on:
179+
- result: passed

.semaphore/server-deploy-k8s.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# This pipeline runs after docker-build.yml
2+
version: v1.0
3+
name: Deploy server to Kubernetes
4+
agent:
5+
machine:
6+
type: e1-standard-2
7+
os_image: ubuntu1804
8+
blocks:
9+
- name: Deploy server to Kubernetes
10+
task:
11+
# Mount a secret which defines /home/semaphore/.kube/dok8s.yaml.
12+
# By mounting it, we make file available in the job environment.
13+
# For info on creating secrets, see:
14+
# https://docs.semaphoreci.com/article/66-environment-variables-and-secrets
15+
secrets:
16+
- name: do-k8s-secret
17+
18+
# Define an environment variable which configures kubectl:
19+
env_vars:
20+
- name: KUBECONFIG
21+
value: /home/semaphore/.kube/dok8s.yaml
22+
jobs:
23+
- name: Deploy
24+
commands:
25+
- checkout
26+
- kubectl get nodes
27+
- kubectl get pods
28+
29+
# Our deployment.yml instructs Kubernetes to pull container image
30+
# named semaphoredemos/semaphore-demo-javascript-server:$SEMAPHORE_WORKFLOW_ID
31+
#
32+
# envsubst is a tool which will replace $SEMAPHORE_WORKFLOW_ID with
33+
# its current value. The same variable was used in server-docker-build.yml
34+
# pipeline to tag and push a container image.
35+
- envsubst < deployment.yml | tee deployment.yml
36+
37+
# Perform declarative deployment:
38+
- kubectl apply -f deployment.yml
39+
40+
# If deployment to production succeeded, let's create a new version of
41+
# our `latest` Docker image.
42+
- name: Tag latest release
43+
task:
44+
secrets:
45+
- name: markoa-dockerhub
46+
jobs:
47+
- name: docker tag latest
48+
commands:
49+
- echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin
50+
- docker pull semaphoredemos/semaphore-demo-javascript-server:$SEMAPHORE_WORKFLOW_ID
51+
- docker tag semaphoredemos/semaphore-demo-javascript-server:$SEMAPHORE_WORKFLOW_ID semaphoredemos/semaphore-demo-javascript-server:latest
52+
- docker push semaphoredemos/semaphore-demo-javascript-server:latest

.semaphore/server-docker-build.yml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# This pipeline runs after semaphore.yml
2+
version: v1.0
3+
name: Docker build server
4+
agent:
5+
machine:
6+
# Use a machine type with more RAM and CPU power for faster container
7+
# builds:
8+
type: e1-standard-4
9+
os_image: ubuntu1804
10+
blocks:
11+
- name: Build
12+
task:
13+
# Mount a secret which defines DOCKER_USERNAME and DOCKER_PASSWORD
14+
# environment variables.
15+
# For info on creating secrets, see:
16+
# https://docs.semaphoreci.com/article/66-environment-variables-and-secrets
17+
secrets:
18+
- name: markoa-dockerhub
19+
jobs:
20+
- name: Docker build
21+
commands:
22+
# Authenticate with Docker Hub
23+
# using environment variables in markoa-dockerhub secret:
24+
- echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin
25+
- checkout
26+
- cd src/server
27+
28+
# Use docker layer caching and reuse unchanged layers to build a new
29+
# container image faster.
30+
# To do that, we first need to pull a previous version of container:
31+
- docker pull semaphoredemos/semaphore-demo-javascript-server:latest || true
32+
33+
# Build a new image based on pulled image, if present.
34+
# Use $SEMAPHORE_WORKFLOW_ID environment variable to produce a
35+
# unique image tag.
36+
# For a list of available environment variables on Semaphore, see:
37+
# https://docs.semaphoreci.com/article/12-environment-variables
38+
- docker build --cache-from semaphoredemos/semaphore-demo-javascript-server:latest -t semaphoredemos/semaphore-demo-javascript-server:$SEMAPHORE_WORKFLOW_ID .
39+
- docker images
40+
41+
# Push a new image to Docker Hub container registry:
42+
- docker push semaphoredemos/semaphore-demo-javascript-server:$SEMAPHORE_WORKFLOW_ID
43+
44+
# The deployment pipeline is defined to run on manual approval from the UI.
45+
# Semaphore will the time and the name of the person who promotes each
46+
# deployment.
47+
#
48+
# You could, for example, add another promotion to a pipeline that
49+
# automatically deploys to a staging environment from branches named
50+
# after a certain pattern.
51+
# https://docs.semaphoreci.com/article/50-pipeline-yaml#promotions
52+
promotions:
53+
- name: Deploy server to Kubernetes
54+
pipeline_file: server-deploy-k8s.yml

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ services:
1111
volumes:
1212
- database_data:/var/lib/postgresql/data
1313
ports:
14-
- 5432:5432
14+
- $POSTGRES_PORT:$POSTGRES_PORT
1515

1616
adminer:
1717
image: adminer

0 commit comments

Comments
 (0)