Skip to content

Commit 1be4a65

Browse files
committed
Initial commit
1 parent 0337667 commit 1be4a65

30 files changed

+2838
-2
lines changed

Diff for: .github/workflows/deploy-app.yaml

+213
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
name: Full CI/CD pipeline
2+
# Use this to this to launch the workflow manually.
3+
on: workflow_dispatch
4+
# Uncomment the following lines to execute the job automatically.
5+
#on:
6+
# push:
7+
# branches: [main]
8+
env:
9+
PLAYGROUND_PAT: ${{ secrets.PLAYGROUND_PRODUCTION_PAT}} #TODO: Store your PAT in this secret, or point to the correct one if it has a different name.
10+
TARGET_DOCKER_REGISTRY: napptive #TODO: This should be your docker hub account.
11+
PLAYGROUND_ACCOUNT_NAME: dhiguero #TODO: This should be your NAPPTIVE username.
12+
jobs:
13+
build:
14+
name: Unit and Integration Tests
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v2
18+
- uses: actions/setup-node@v2
19+
with:
20+
node-version: '17'
21+
- run: npm install
22+
- run: npm test
23+
upload-docker-revision:
24+
needs: build
25+
name: Push docker images
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v2
29+
- name: Docker Login
30+
uses: docker/login-action@v1
31+
with:
32+
username: ${{secrets.DOCKER_HUB_USER}}
33+
password: ${{secrets.DOCKER_HUB_TOKEN}}
34+
- name: Build and push Docker images
35+
run: make docker-push
36+
upload-app-def-revision:
37+
needs: upload-docker-revision
38+
name: Push the application definitions to the NAPPTIVE catalog
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: actions/checkout@v2
42+
- name: Render Kubernetes OAM files
43+
run: make k8s
44+
- name: Get Version
45+
id: version
46+
run: echo "::set-output name=version::$(cat version)"
47+
- name: Push the application to the catalog
48+
uses: napptive-actions/[email protected]
49+
with:
50+
applicationPath: ./build/k8s/todoapp
51+
namespace: "napptive"
52+
applicationName: "example-app-nodejs"
53+
tag: ${{ steps.version.outputs.version }}
54+
- name: Push the acceptance test runner to the catalog
55+
uses: napptive-actions/[email protected]
56+
with:
57+
applicationPath: ./build/k8s/todoat
58+
namespace: "napptive"
59+
applicationName: "example-app-nodejs-at"
60+
tag: ${{ steps.version.outputs.version }}
61+
prepare-acceptance-test-env:
62+
needs: [upload-app-def-revision, upload-docker-revision]
63+
name: Prepare the environment to launch AT
64+
runs-on: ubuntu-latest
65+
outputs:
66+
envname: ${{ steps.envname.outputs.envname }}
67+
steps:
68+
- uses: actions/checkout@v2
69+
- name: Get Version
70+
id: version
71+
run: echo "::set-output name=version::$(cat version)"
72+
- name: Set environment name
73+
id: envname
74+
run: echo "::set-output name=envname::${PLAYGROUND_ACCOUNT_NAME}/todo-at-${GITHUB_RUN_ID}"
75+
- name: Create test environment
76+
uses: napptive-actions/[email protected]
77+
with:
78+
cmd: "env create ${{steps.envname.outputs.envname }}"
79+
launch-acceptance-tests:
80+
needs: prepare-acceptance-test-env
81+
name: Launch the acceptance tests
82+
runs-on: ubuntu-latest
83+
steps:
84+
- uses: actions/checkout@v2
85+
- name: Get Version
86+
id: get-version
87+
run: echo "::set-output name=version::$(cat version)"
88+
- name: Deploy the TODO app from the catalog
89+
uses: napptive-actions/[email protected]
90+
with:
91+
appName: napptive/example-app-nodejs:${{ steps.get-version.outputs.version }}
92+
environment: ${{needs.prepare-acceptance-test-env.outputs.envname}}
93+
- name: Wait for TODO app
94+
uses: napptive-actions/[email protected]
95+
with:
96+
cmd: "apps wait example-app-nodejs"
97+
environment: ${{needs.prepare-acceptance-test-env.outputs.envname}}
98+
- name: Deploy the TODO app AT runner from the catalog
99+
uses: napptive-actions/[email protected]
100+
with:
101+
appName: napptive/example-app-nodejs-at:${{ steps.get-version.outputs.version }}
102+
environment: ${{needs.prepare-acceptance-test-env.outputs.envname}}
103+
- name: Wait for the test runner
104+
uses: napptive-actions/[email protected]
105+
continue-on-error: true
106+
id: wait-at
107+
with:
108+
cmd: "apps wait example-app-nodejs-at --logContains TEST_SUCCESS --timeout=30s"
109+
environment: ${{needs.prepare-acceptance-test-env.outputs.envname}}
110+
- name: AT success
111+
id: at-success
112+
run: echo '::set-output name=at-result::true'
113+
if: steps.wait-at.outcome == 'success'
114+
- name: AT failure
115+
id: at-failure
116+
run: echo '::set-output name=at-result::false'
117+
if: steps.wait-at.outcome == 'failure'
118+
cleanup-acceptance-test-env:
119+
if: ${{ always() }}
120+
needs: [prepare-acceptance-test-env, launch-acceptance-tests]
121+
name: Cleanup acceptance test environment
122+
runs-on: ubuntu-latest
123+
steps:
124+
- uses: actions/checkout@v2
125+
- name: Remove todo app
126+
uses: napptive-actions/[email protected]
127+
continue-on-error: true
128+
with:
129+
cmd: "apps remove example-app-nodejs"
130+
environment: ${{needs.prepare-acceptance-test-env.outputs.envname}}
131+
- name: Remove AT app
132+
uses: napptive-actions/[email protected]
133+
continue-on-error: true
134+
with:
135+
cmd: "apps remove example-app-nodejs-at"
136+
environment: ${{needs.prepare-acceptance-test-env.outputs.envname}}
137+
- name: Cleanup test environment
138+
uses: napptive-actions/[email protected]
139+
continue-on-error: true
140+
with:
141+
cmd: "env remove ${{needs.prepare-acceptance-test-env.outputs.envname}}"
142+
create-prod-env:
143+
needs: [launch-acceptance-tests]
144+
name: Create the production environment
145+
runs-on: ubuntu-latest
146+
outputs:
147+
envname: ${{ steps.envname.outputs.envname }}
148+
steps:
149+
- uses: actions/checkout@v2
150+
- name: Set environment name
151+
id: envname
152+
run: echo "::set-output name=envname::${PLAYGROUND_ACCOUNT_NAME}/todo-app-prod"
153+
- name: Create production environment
154+
uses: napptive-actions/[email protected]
155+
continue-on-error: true
156+
with:
157+
cmd: "env create ${{steps.envname.outputs.envname }}"
158+
check-app-deployed:
159+
needs: [create-prod-env]
160+
name: Check if the application is deployed
161+
runs-on: ubuntu-latest
162+
outputs:
163+
not-found: ${{ steps.not-found.outputs.not-found }}
164+
found: ${{ steps.found.outputs.found }}
165+
steps:
166+
- uses: actions/checkout@v2
167+
- name: Check if the app exists
168+
uses: napptive-actions/[email protected]
169+
continue-on-error: true
170+
id: check
171+
with:
172+
cmd: "apps info example-app-nodejs"
173+
environment: ${{needs.create-prod-env.outputs.envname}}
174+
- name: Set App not found
175+
id: not-found
176+
run: echo '::set-output name=not-found::true'
177+
if: steps.check.outcome != 'success'
178+
- name: Set App found
179+
id: found
180+
run: echo '::set-output name=found::true'
181+
if: steps.check.outcome != 'failure'
182+
deploy-app:
183+
name: Deploy application into production
184+
needs: [create-prod-env, check-app-deployed]
185+
runs-on: ubuntu-latest
186+
if: ${{needs.check-app-deployed.outputs.not-found == 'true'}}
187+
steps:
188+
- uses: actions/checkout@v2
189+
- name: Get Version
190+
id: get-version
191+
run: echo "::set-output name=version::$(cat version)"
192+
- name: Deploy the app from the catalog
193+
uses: napptive-actions/[email protected]
194+
with:
195+
appName: napptive/example-app-nodejs:${{ steps.get-version.outputs.version }}
196+
environment: ${{needs.create-prod-env.outputs.envname}}
197+
update-app:
198+
name: Update application
199+
needs: [create-prod-env, check-app-deployed]
200+
runs-on: ubuntu-latest
201+
if: ${{needs.check-app-deployed.outputs.found == 'true'}}
202+
steps:
203+
- uses: actions/checkout@v2
204+
- name: Make scripts executable
205+
run: chmod +x updateImage.sh
206+
- name: Get Version
207+
id: version
208+
run: echo "::set-output name=version::$(cat version)"
209+
- name: Deploy new version of the application
210+
run: ./updateImage.sh
211+
env:
212+
VERSION: ${{ steps.version.outputs.version }}
213+
ENV_NAME: ${{needs.create-prod-env.outputs.envname}}

Diff for: .github/workflows/remove-app.yaml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Cleanup production environment
2+
# This workflow is intended to be executed manually.
3+
on: workflow_dispatch
4+
env:
5+
PLAYGROUND_PAT: ${{ secrets.PLAYGROUND_PRODUCTION_PAT}} #TODO: Store your PAT in this secret, or point to the correct one if it has a different name.
6+
PLAYGROUND_ACCOUNT_NAME: dhiguero #TODO: This should be your NAPPTIVE username.
7+
jobs:
8+
delete-prod-app:
9+
name: Delete the production application and its environment.
10+
runs-on: ubuntu-latest
11+
outputs:
12+
envname: ${{ steps.envname.outputs.envname }}
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Set environment name
16+
id: envname
17+
run: echo "::set-output name=envname::${PLAYGROUND_ACCOUNT_NAME}/todo-app-prod"
18+
- name: Remove todo app
19+
uses: napptive-actions/[email protected]
20+
continue-on-error: true
21+
with:
22+
cmd: "apps remove example-app-nodejs"
23+
environment: ${{steps.envname.outputs.envname}}
24+
playgroundConfigFile: ./config/playground.yaml
25+
- name: Delete production environment
26+
uses: napptive-actions/[email protected]
27+
continue-on-error: true
28+
with:
29+
cmd: "env delete ${{steps.envname.outputs.envname }}"
30+
playgroundConfigFile: ./config/playground.yaml

Diff for: .gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Directory with binary and compile resources
2+
build/
3+
4+
node_modules/

Diff for: Dockerfile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM node:16
2+
3+
# Create app directory
4+
WORKDIR /usr/src/app
5+
6+
# Install app dependencies
7+
# A wildcard is used to ensure both package.json AND package-lock.json are copied
8+
# where available (npm@5+)
9+
COPY package*.json ./
10+
11+
RUN npm install
12+
# If you are building your code for production
13+
# RUN npm ci --only=production
14+
15+
# Bundle app source
16+
COPY . .
17+
18+
EXPOSE 8080
19+
CMD [ "node", "server.js" ]

Diff for: Dockerfile.newman

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM postman/newman:5-alpine
2+
3+
# Acceptance test directory
4+
WORKDIR /at
5+
6+
COPY acceptance.postman.json .
7+
COPY launchAT.sh .
8+
RUN chmod +x launchAT.sh
9+
10+
ENTRYPOINT ["./launchAT.sh"]

Diff for: Makefile

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#Version must be overrided in the CI
2+
VERSION=$(shell cat version)
3+
4+
# Docker options
5+
TARGET_DOCKER_REGISTRY ?= $$USER
6+
7+
# Variables
8+
BUILD_FOLDER=$(CURDIR)/build
9+
BIN_FOLDER=$(BUILD_FOLDER)/bin
10+
DOCKER_FOLDER=$(BUILD_FOLDER)/docker
11+
K8S_FOLDER=$(BUILD_FOLDER)/k8s
12+
13+
UNAME := $(shell uname)
14+
ifeq ($(UNAME), Darwin)
15+
SED := gsed
16+
else
17+
SED := sed
18+
endif
19+
20+
#Docker command
21+
DOCKERCMD?=docker
22+
23+
# Tools
24+
NPM_CMD=ng
25+
NPM_BUILD=$(NG_CMD) build
26+
NPM_TEST=$(NG_CMD) test
27+
28+
.PHONY: clean
29+
# Remove build files
30+
clean:
31+
@echo "Cleaining build folder: $(BUILD_FOLDER)"
32+
@rm -rf $(BUILD_FOLDER)
33+
34+
.PHONY: test
35+
test:
36+
@echo "Executing tests"
37+
@$(NPM_TEST)
38+
39+
.PHONY: docker-build
40+
docker-build: docker-build-api docker-build-at
41+
42+
.PHONY: docker-build-api
43+
docker-build-api:
44+
$(DOCKERCMD) build --platform linux/amd64 -t $(TARGET_DOCKER_REGISTRY)/example-app-nodejs-api:$(VERSION) .
45+
46+
.PHONY: docker-build-at
47+
docker-build-at:
48+
$(DOCKERCMD) build -f Dockerfile.newman --platform linux/amd64 -t $(TARGET_DOCKER_REGISTRY)/example-app-nodejs-api-at-runner:$(VERSION) .
49+
50+
.PHONY: docker-push
51+
docker-push: docker-build
52+
@echo Pushing example-app-nodejs Docker images to DockerHub
53+
$(DOCKERCMD) push $(TARGET_DOCKER_REGISTRY)/example-app-nodejs-api:$(VERSION) || exit 1;
54+
$(DOCKERCMD) push $(TARGET_DOCKER_REGISTRY)/example-app-nodejs-api-at-runner:$(VERSION) || exit 1;
55+
56+
.PHONY: k8s
57+
k8s:
58+
@rm -r $(K8S_FOLDER) || true
59+
@mkdir -p $(K8S_FOLDER)
60+
@mkdir -p $(K8S_FOLDER)/todoapp
61+
@mkdir -p $(K8S_FOLDER)/todoat
62+
@cp deployments/todoapp/* $(K8S_FOLDER)/todoapp/.
63+
@cp deployments/todoat/* $(K8S_FOLDER)/todoat/.
64+
@$(SED) -i 's/TARGET_DOCKER_REGISTRY/'$(TARGET_DOCKER_REGISTRY)'/' $(K8S_FOLDER)/todoapp/*.yaml
65+
@$(SED) -i 's/TARGET_DOCKER_REGISTRY/'$(TARGET_DOCKER_REGISTRY)'/' $(K8S_FOLDER)/todoat/*.yaml
66+
@$(SED) -i 's/VERSION/$(VERSION)/' $(K8S_FOLDER)/todoapp/*.yaml
67+
@$(SED) -i 's/VERSION/$(VERSION)/' $(K8S_FOLDER)/todoat/*.yaml
68+
@echo "Kubernetes files ready at $(K8S_FOLDER)/"

0 commit comments

Comments
 (0)