Skip to content

Commit da8e769

Browse files
heikergilsantii90ec
authored andcommitted
parent bf8977e
author Heiker Gil <[email protected]> 1646927329 -0500 committer Santiago Atapuma <[email protected]> 1647463991 -0500 parent bf8977e author Heiker Gil <[email protected]> 1646927329 -0500 committer Santiago Atapuma <[email protected]> 1647463401 -0500 fix: TT-513 CI/CD fix files feat: TT-513 cd-stage workflows feat: TT-513 fix indent cd-stage.yml feat: TT-513 fix indent cd-stage.yml fix: TT-513 fix indent cd-stage.yml feat: TT-513 add ci.yml feat: TT-513 add ci.yml fix: TT-513 fix ci.yml fix: TT-513 ci.yml feat: TT-513 add cd-prod.yml Update time-tracker-ui-ci.yml fix: TT-513 ci.yml Update time-tracker-ui-ci.yml feat: TT-513 environment variables fix: TT-513 .env variables fix: TT-513 env variables fix: TT-513 fix make file fix: TT-513 install chrome with dockerfile fix: TT-513 install chrome on docker container fix: TT-513 fix docker file fix: karma.conf.js to run headless fix: TT-513 change tests to ci-test scrip fix: TT-513 fix docker file fix: TT-513 karma testing fix: TT-513 add chrome to docker img fix: TT-513 change chrome download url fix: TT-513 fix chorme install fix: TT-513 change make to ci-test fix: TT-513 fix coverage fix: TT-513 fix permissions fix: TT-513 Fix Permissions in home fix: TT-513 fix permissions fix: TT-513 fix permissions fix: TT-573 fix permission} fix: TT-513 fix permissions fix: TT-573 fix permissions fix: TT-513 Fix permissions fix: TT-513 fix permissions fix: TT-513 Fix Permissions fix: TT-513 Fix Permissions fix: TT-513 Permissions fix: TT-513 disable karma coverage test fix: TT-513 Fix CLI
1 parent a4b8426 commit da8e769

File tree

9 files changed

+312
-20
lines changed

9 files changed

+312
-20
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: time-tracker-ui-cd-prod
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
jobs:
9+
cd:
10+
runs-on: ubuntu-latest
11+
env:
12+
TF_WORKSPACE: prod
13+
WORKING_DIR: infrastructure/
14+
ARM_CLIENT_ID: ${{secrets.TF_ARM_CLIENT_ID}}
15+
ARM_CLIENT_SECRET: ${{secrets.TF_ARM_CLIENT_SECRET}}
16+
ARM_SUBSCRIPTION_ID: ${{secrets.TF_ARM_SUBSCRIPTION_ID}}
17+
ARM_TENANT_ID: ${{secrets.TF_ARM_TENANT_ID}}
18+
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v3
22+
23+
- name: Get the release_version
24+
run: |
25+
echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
26+
echo $RELEASE_VERSION
27+
- name: Login to azure
28+
uses: Azure/login@v1
29+
with:
30+
creds: ${{ secrets.AZURE_CREDENTIALS }}
31+
32+
- name: Build the docker image
33+
run: make build
34+
35+
- name: Publish docker image to prod azure container registry
36+
run: |
37+
make login publish acr=timetrackerserviceprodregistry image_tag=$RELEASE_VERSION
38+
- name: Setup terraform
39+
uses: hashicorp/setup-terraform@v1
40+
41+
- name: Authenticate with the TF modules repository
42+
uses: webfactory/[email protected]
43+
with:
44+
ssh-private-key: ${{ secrets.INFRA_TERRAFORM_MODULES_SSH_PRIV_KEY }}
45+
46+
- name: Terraform Init
47+
working-directory: ${{ env.WORKING_DIR }}
48+
run: terraform init
49+
50+
- name: Terraform Apply
51+
working-directory: ${{ env.WORKING_DIR }}
52+
run: terraform apply -lock=false -var-file="${{ env.TF_WORKSPACE }}.tfvars" -var "image_tag=$RELEASE_VERSION" -auto-approve
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: time-tracker-ui-cd-stage
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
jobs:
9+
cd:
10+
runs-on: ubuntu-latest
11+
env:
12+
TF_WORKSPACE: stage
13+
WORKING_DIR: infrastructure/
14+
ARM_CLIENT_ID: ${{secrets.TF_ARM_CLIENT_ID}}
15+
ARM_CLIENT_SECRET: ${{secrets.TF_ARM_CLIENT_SECRET}}
16+
ARM_SUBSCRIPTION_ID: ${{secrets.TF_ARM_SUBSCRIPTION_ID}}
17+
ARM_TENANT_ID: ${{secrets.TF_ARM_TENANT_ID}}
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v3
21+
- name: Get the release_version
22+
run: |
23+
echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
24+
echo $RELEASE_VERSION
25+
- name: Login to azure
26+
uses: Azure/login@v1
27+
with:
28+
creds: ${{ secrets.AZURE_CREDENTIALS }}
29+
- name: Build the docker image
30+
run: make build
31+
- name: Publish docker image to stage azure container registry
32+
run: |
33+
make login publish acr=timetrackerservicestageregistry image_tag=$RELEASE_VERSION
34+
- name: Setup terraform
35+
uses: hashicorp/setup-terraform@v1
36+
- name: Authenticate with the TF modules repository
37+
uses: webfactory/[email protected]
38+
with:
39+
ssh-private-key: ${{ secrets.INFRA_TERRAFORM_MODULES_SSH_PRIV_KEY }}
40+
- name: Terraform Init
41+
working-directory: ${{ env.WORKING_DIR }}
42+
run: terraform init
43+
- name: Terraform Apply
44+
working-directory: ${{ env.WORKING_DIR }}
45+
run: terraform apply -lock=false -var-file="${{ env.TF_WORKSPACE }}.tfvars" -var "image_tag=$RELEASE_VERSION" -auto-approve
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
name: time-tracker-ui-ci
2+
3+
on:
4+
push:
5+
branches:
6+
- TT-513-Create-CI/CD-pipeline-in-timer-tracker-ui-to-deploy-changes-for-both-environments
7+
8+
pull_request:
9+
branches:
10+
- master
11+
12+
jobs:
13+
ci:
14+
runs-on: ubuntu-latest
15+
env:
16+
WORKING_DIR: infrastructure/
17+
DB_CONNECTION: ${{ secrets.DB_CONNECTION }}
18+
ARM_CLIENT_ID: ${{secrets.TF_ARM_CLIENT_ID}}
19+
ARM_CLIENT_SECRET: ${{secrets.TF_ARM_CLIENT_SECRET}}
20+
ARM_SUBSCRIPTION_ID: ${{secrets.TF_ARM_SUBSCRIPTION_ID}}
21+
ARM_TENANT_ID: ${{secrets.TF_ARM_TENANT_ID}}
22+
strategy:
23+
max-parallel: 5
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v3
27+
28+
- name: Authenticate with the TF modules repository
29+
uses: webfactory/[email protected]
30+
with:
31+
ssh-private-key: ${{ secrets.INFRA_TERRAFORM_MODULES_SSH_PRIV_KEY }}
32+
33+
# ci-test:
34+
# name: Unit tests and CodeCoverage
35+
# timeout-minutes: 90
36+
# steps:
37+
# - name: Set up Node.js version
38+
# uses: actions/setup-node@v1
39+
# with:
40+
# node-version: '12.x'
41+
42+
# - name: Install dependencies
43+
# run: npm install
44+
45+
- name: build docker
46+
run: make build
47+
48+
- name: Inject Secrets
49+
env:
50+
SCOPES: ${{ secrets.SCOPES }}
51+
CLIENT_ID: ${{ secrets.CLIENT_ID }}
52+
AUTHORITY: ${{ secrets.AUTHORITY }}
53+
STACK_EXCHANGE_ID: ${{ secrets.STACK_EXCHANGE_ID }}
54+
STACK_EXCHANGE_ACCESS_TOKEN: ${{ secrets.STACK_EXCHANGE_ACCESS_TOKEN }}
55+
AZURE_APP_CONFIGURATION_CONNECTION_STRING: ${{ secrets.AZURE_APP_CONFIGURATION_CONNECTION_STRING }}
56+
run: |
57+
chmod +x ./scripts/populate-keys.sh
58+
sh ./scripts/populate-keys.sh
59+
60+
- name: Running tests
61+
run: |
62+
chmod -R 777 ./$home
63+
make test
64+
- name: Generate coverage report
65+
env:
66+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
67+
run: bash <(curl -s https://codecov.io/bash)
68+
69+
- name: Setup terraform
70+
uses: hashicorp/setup-terraform@v1
71+
72+
- name: 'Terraform Init'
73+
id: init
74+
working-directory: ./${{ env.WORKING_DIR }}
75+
run: terraform init
76+
77+
- name: 'Terraform validate'
78+
id: validate
79+
working-directory: ./${{ env.WORKING_DIR }}
80+
run: terraform validate
81+
82+
- name: Terraform Plan Stage
83+
id: plan-stage
84+
if: github.event_name == 'pull_request'
85+
run: terraform plan -var-file=${{ env.TF_WORKSPACE }}.tfvars -no-color
86+
continue-on-error: true
87+
working-directory: ./${{ env.WORKING_DIR }}
88+
env:
89+
TF_WORKSPACE: stage
90+
91+
- name: Terraform Plan Prod
92+
id: plan-prod
93+
if: github.event_name == 'pull_request'
94+
run: terraform plan -var-file=${{ env.TF_WORKSPACE }}.tfvars -no-color
95+
continue-on-error: true
96+
working-directory: ./${{ env.WORKING_DIR }}
97+
env:
98+
TF_WORKSPACE: prod
99+
100+
- name: Update Pull Request with Stage Plan
101+
uses: actions/[email protected]
102+
if: github.event_name == 'pull_request'
103+
env:
104+
PLAN: "terraform\n${{ steps.plan-stage.outputs.stdout }}"
105+
TF_WORKSPACE: stage
106+
with:
107+
github-token: ${{ secrets.GITHUB_TOKEN }}
108+
script: |
109+
const output = `#### [${{ env.WORKING_DIR }}][${{ env.TF_WORKSPACE }}] Terraform Plan 📖 \`${{ steps.plan-stage.outcome }}\`
110+
<details><summary>Show Plan</summary>
111+
\`\`\`\n
112+
${process.env.PLAN}
113+
\`\`\`
114+
</details>
115+
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
116+
github.issues.createComment({
117+
issue_number: context.issue.number,
118+
owner: context.repo.owner,
119+
repo: context.repo.repo,
120+
body: output
121+
})
122+
- name: Update Pull Request with Prod Plan
123+
uses: actions/[email protected]
124+
if: github.event_name == 'pull_request'
125+
env:
126+
PLAN: "terraform\n${{ steps.plan-prod.outputs.stdout }}"
127+
TF_WORKSPACE: prod
128+
with:
129+
github-token: ${{ secrets.GITHUB_TOKEN }}
130+
script: |
131+
const output = `#### [${{ env.WORKING_DIR }}][${{ env.TF_WORKSPACE }}] Terraform Plan 📖 \`${{ steps.plan-prod.outcome }}\`
132+
<details><summary>Show Plan</summary>
133+
\`\`\`\n
134+
${process.env.PLAN}
135+
\`\`\`
136+
</details>
137+
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
138+
github.issues.createComment({
139+
issue_number: context.issue.number,
140+
owner: context.repo.owner,
141+
repo: context.repo.repo,
142+
body: output
143+
})
144+
- name: Terraform Plan Stage Status
145+
if: steps.plan-stage.outcome == 'failure'
146+
run: exit 1
147+
148+
- name: Terraform Plan Prod Status
149+
if: steps.plan-prod.outcome == 'failure'
150+
run: exit 1

Dockerfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,43 @@ FROM node:14 AS development
22

33
ENV USERNAME timetracker
44
ENV HOME /home/${USERNAME}
5+
ENV CHROME_BIN /opt/google/chrome/google-chrome
6+
#Essential tools and xvfb
7+
RUN apt-get update && apt-get install -y \
8+
software-properties-common \
9+
unzip \
10+
curl \
11+
wget \
12+
xvfb
13+
14+
#Chrome browser to run the tests
15+
ARG CHROME_VERSION=65.0.3325.181
16+
RUN curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add \
17+
&& wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
18+
&& dpkg -i google-chrome-stable_current_amd64.deb || true
19+
RUN apt-get install -y -f \
20+
&& rm -rf /var/lib/apt/lists/*
21+
22+
#Disable the SUID sandbox so that chrome can launch without being in a privileged container
23+
RUN dpkg-divert --add --rename --divert /opt/google/chrome/google-chrome.real /opt/google/chrome/google-chrome \
24+
&& echo "#! /bin/bash\nexec /opt/google/chrome/google-chrome.real --no-sandbox --disable-setuid-sandbox \"\$@\"" > /opt/google/chrome/google-chrome \
25+
&& chmod 755 /opt/google/chrome/google-chrome
26+
27+
#Chrome Driver
28+
ARG CHROME_DRIVER_VERSION=2.37
29+
RUN mkdir -p /opt/selenium \
30+
&& curl http://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip -o /opt/selenium/chromedriver_linux64.zip \
31+
&& cd /opt/selenium; unzip /opt/selenium/chromedriver_linux64.zip; rm -rf chromedriver_linux64.zip; ln -fs /opt/selenium/chromedriver /usr/local/bin/chromedriver;
532

633
RUN useradd -ms /bin/bash ${USERNAME}
734

835
WORKDIR ${HOME}/time-tracker-ui
936
COPY . .
1037
RUN rm -f .env
1138
RUN chown ${USERNAME}:${USERNAME} -R ${HOME}/time-tracker-ui
39+
RUN chmod -R 777 ${HOME}/time-tracker-ui
40+
41+
1242

1343
USER ${USERNAME}
1444
RUN npm cache clean --force && npm install

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ remove: ## Delete container timetracker_ui.
4141
.PHONY: test
4242
test: ## Run all tests on docker container timetracker_ui.
4343
docker-compose --env-file ./.env up -d
44-
docker exec -it timetracker_ui bash -c "npm run test"
44+
docker exec -i timetracker_ui bash -c "npm run ci-test"
4545

4646
.PHONY: publish
4747
publish: ## Publish the container image timetracker_ui.

docker-compose.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ services:
1111
- 4200:4200
1212
- 9876:9876
1313
environment:
14+
CHROME_BIN: /opt/google/chrome/google-chrome
1415
AUTHORITY: ${AUTHORITY}
1516
CLIENT_ID: ${CLIENT_ID}
1617
SCOPES: ${SCOPES}
@@ -20,12 +21,12 @@ services:
2021
AUTHORITY_JSON: ${AUTHORITY_JSON}
2122
CLIENT_ID_JSON: ${CLIENT_ID_JSON}
2223
SCOPES_JSON: ${SCOPES_JSON}
23-
volumes:
24-
- ./src:/home/timetracker/time-tracker-ui/src/
25-
- ./scripts:/home/timetracker/time-tracker-ui/scripts/
26-
- ./e2e:/home/timetracker/time-tracker-ui/e2e/
27-
- ./coverage:/home/timetracker/time-tracker-ui/coverage
28-
- ./angular.json:/home/timetracker/time-tracker-ui/angular.json
29-
- ./karma.conf.js:/home/timetracker/time-tracker-ui/karma.conf.js
30-
- ./package.json:/home/timetracker/time-tracker-ui/package.json
31-
- ./webpack.config.js:/home/timetracker/time-tracker-ui/webpack.config.js
24+
# volumes:
25+
# # - ./src:/home/timetracker/time-tracker-ui/src/
26+
# # - ./scripts:/home/timetracker/time-tracker-ui/scripts/
27+
# # - ./e2e:/home/timetracker/time-tracker-ui/e2e/
28+
# # - ./coverage:/home/timetracker/time-tracker-ui/coverage
29+
# # - ./angular.json:/home/timetracker/time-tracker-ui/angular.json
30+
# # - ./karma.conf.js:/home/timetracker/time-tracker-ui/karma.conf.js
31+
# # - ./package.json:/home/timetracker/time-tracker-ui/package.json
32+
# # - ./webpack.config.js:/home/timetracker/time-tracker-ui/webpack.config.js

e2e/protractor.conf.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@ exports.config = {
1313
'./src/**/*.e2e-spec.ts'
1414
],
1515
capabilities: {
16-
browserName: 'chrome'
16+
browserName: 'chrome',
17+
'chromeOptions': {
18+
'args': [
19+
'--no-sandbox',
20+
'--headless',
21+
'--window-size=1024,768'
22+
]
23+
}
1724
},
1825
directConnect: true,
1926
baseUrl: 'http://localhost:4200/',
@@ -29,4 +36,4 @@ exports.config = {
2936
});
3037
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
3138
}
32-
};
39+
};

karma.conf.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Karma configuration file, see link for more information
22
// https://karma-runner.github.io/1.0/config/configuration-file.html
33

4+
45
module.exports = function (config) {
56
config.set({
67
basePath: '',
@@ -21,6 +22,12 @@ module.exports = function (config) {
2122
seed: '90967',
2223
}, // leave Jasmine Spec Runner output visible in browser
2324
},
25+
// Karma Typescript compiler options
26+
karmaTypescriptConfig: {
27+
coverageOptions : {
28+
instrumentation: false
29+
}
30+
},
2431
coverageIstanbulReporter: {
2532
dir: require('path').join(__dirname, './coverage/time-tracker'),
2633
reports: ['html', 'lcovonly', 'text-summary'],

scripts/populate-keys.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/bin/bash
22

3-
> src/environments/keys.ts
4-
echo 'export const AUTHORITY = "'$AUTHORITY'";' >> src/environments/keys.ts
5-
echo 'export const CLIENT_ID = "'$CLIENT_ID'";' >> src/environments/keys.ts
6-
echo 'export const SCOPES = ["'$SCOPES'"];' >> src/environments/keys.ts
7-
echo 'export const STACK_EXCHANGE_ID = "'$STACK_EXCHANGE_ID'";' >> src/environments/keys.ts
8-
echo 'export const STACK_EXCHANGE_ACCESS_TOKEN = "'$STACK_EXCHANGE_ACCESS_TOKEN'";' >> src/environments/keys.ts
9-
echo 'export const AZURE_APP_CONFIGURATION_CONNECTION_STRING = "'$AZURE_APP_CONFIGURATION_CONNECTION_STRING'";' >> src/environments/keys.ts
10-
cat src/environments/keys.ts
3+
> .env
4+
echo 'AUTHORITY = '$AUTHORITY'' >> .env
5+
echo 'CLIENT_ID = '$CLIENT_ID'' >> .env
6+
echo 'SCOPES = '$SCOPES'' >> .env
7+
echo 'STACK_EXCHANGE_ID = '$STACK_EXCHANGE_ID'' >> .env
8+
echo 'STACK_EXCHANGE_ACCESS_TOKEN = '$STACK_EXCHANGE_ACCESS_TOKEN'' >> .env
9+
echo 'AZURE_APP_CONFIGURATION_CONNECTION_STRING = '$AZURE_APP_CONFIGURATION_CONNECTION_STRING'' >> .env
10+
cat .env

0 commit comments

Comments
 (0)