Skip to content

Commit 51c2d5e

Browse files
committed
Resolve mMerge changes
2 parents 29f5c07 + da1792f commit 51c2d5e

19 files changed

+24933
-24618
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
28+
- name: Login to azure
29+
uses: Azure/login@v1
30+
with:
31+
creds: ${{ secrets.AZURE_CREDENTIALS }}
32+
33+
- name: Build the docker image
34+
run: make build
35+
36+
- name: Publish docker image to prod azure container registry
37+
run: |
38+
make login publish acr=timetrackerserviceprodregistry image_tag=$RELEASE_VERSION
39+
40+
- name: Setup terraform
41+
uses: hashicorp/setup-terraform@v1
42+
43+
- name: Authenticate with the TF modules repository
44+
uses: webfactory/[email protected]
45+
with:
46+
ssh-private-key: ${{ secrets.INFRA_TERRAFORM_MODULES_SSH_PRIV_KEY }}
47+
48+
- name: Terraform Init
49+
working-directory: ${{ env.WORKING_DIR }}
50+
run: terraform init
51+
52+
- name: Terraform Apply
53+
working-directory: ${{ env.WORKING_DIR }}
54+
run: terraform apply -lock=false -var-file="${{ env.TF_WORKSPACE }}.tfvars" -var "image_tag=$RELEASE_VERSION" -auto-approve
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
22+
- name: Get the release_version
23+
run: |
24+
echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
25+
echo $RELEASE_VERSION
26+
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 stage azure container registry
36+
run: |
37+
make login publish acr=timetrackerservicestageregistry image_tag=$RELEASE_VERSION
38+
39+
- name: Setup terraform
40+
uses: hashicorp/setup-terraform@v1
41+
42+
- name: Authenticate with the TF modules repository
43+
uses: webfactory/[email protected]
44+
with:
45+
ssh-private-key: ${{ secrets.INFRA_TERRAFORM_MODULES_SSH_PRIV_KEY }}
46+
47+
- name: Terraform Init
48+
working-directory: ${{ env.WORKING_DIR }}
49+
run: terraform init
50+
51+
- name: Terraform Apply
52+
working-directory: ${{ env.WORKING_DIR }}
53+
run: terraform apply -lock=false -var-file="${{ env.TF_WORKSPACE }}.tfvars" -var "image_tag=$RELEASE_VERSION" -auto-approve
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
name: time-tracker-ui-ci
2+
3+
on:
4+
push:
5+
branches:
6+
- "**"
7+
8+
pull_request:
9+
branches:
10+
- "**"
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+
- name: build docker
34+
run: make build
35+
36+
- name: Inject Secrets
37+
env:
38+
SCOPES: ${{ secrets.SCOPES }}
39+
CLIENT_ID: ${{ secrets.CLIENT_ID }}
40+
AUTHORITY: ${{ secrets.AUTHORITY }}
41+
STACK_EXCHANGE_ID: ${{ secrets.STACK_EXCHANGE_ID }}
42+
STACK_EXCHANGE_ACCESS_TOKEN: ${{ secrets.STACK_EXCHANGE_ACCESS_TOKEN }}
43+
AZURE_APP_CONFIGURATION_CONNECTION_STRING: ${{ secrets.AZURE_APP_CONFIGURATION_CONNECTION_STRING }}
44+
run: |
45+
chmod +x ./scripts/populate-keys.sh
46+
sh ./scripts/populate-keys.sh
47+
48+
- name: Running tests
49+
run: |
50+
chmod -R 777 ./$home
51+
make test
52+
- name: Generate coverage report
53+
env:
54+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
55+
run: bash <(curl -s https://codecov.io/bash)
56+
57+
- name: Setup terraform
58+
uses: hashicorp/setup-terraform@v1
59+
60+
- name: 'Terraform Init'
61+
id: init
62+
working-directory: ./${{ env.WORKING_DIR }}
63+
run: terraform init
64+
65+
- name: 'Terraform validate'
66+
id: validate
67+
working-directory: ./${{ env.WORKING_DIR }}
68+
run: terraform validate
69+
70+
- name: Terraform Plan Stage
71+
id: plan-stage
72+
run: terraform plan -var-file=${{ env.TF_WORKSPACE }}.tfvars -var image_tag=latest -no-color
73+
continue-on-error: true
74+
working-directory: ./${{ env.WORKING_DIR }}
75+
env:
76+
TF_WORKSPACE: stage
77+
78+
- name: Terraform Plan Prod
79+
id: plan-prod
80+
run: terraform plan -var-file=${{ env.TF_WORKSPACE }}.tfvars -var image_tag=latest -no-color
81+
continue-on-error: true
82+
working-directory: ./${{ env.WORKING_DIR }}
83+
env:
84+
TF_WORKSPACE: prod
85+
86+
- name: Update Pull Request with Stage Plan
87+
uses: actions/[email protected]
88+
if: github.event_name == 'pull_request'
89+
env:
90+
PLAN: "terraform\n${{ steps.plan-stage.outputs.stdout }}"
91+
TF_WORKSPACE: stage
92+
with:
93+
github-token: ${{ secrets.GITHUB_TOKEN }}
94+
script: |
95+
const output = `#### [${{ env.WORKING_DIR }}][${{ env.TF_WORKSPACE }}] Terraform Plan 📖 \`${{ steps.plan-stage.outcome }}\`
96+
<details><summary>Show Plan</summary>
97+
\`\`\`\n
98+
${process.env.PLAN}
99+
\`\`\`
100+
</details>
101+
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
102+
github.issues.createComment({
103+
issue_number: context.issue.number,
104+
owner: context.repo.owner,
105+
repo: context.repo.repo,
106+
body: output
107+
})
108+
109+
- name: Update Pull Request with Prod Plan
110+
uses: actions/[email protected]
111+
if: github.event_name == 'pull_request'
112+
env:
113+
PLAN: "terraform\n${{ steps.plan-prod.outputs.stdout }}"
114+
TF_WORKSPACE: prod
115+
with:
116+
github-token: ${{ secrets.GITHUB_TOKEN }}
117+
script: |
118+
const output = `#### [${{ env.WORKING_DIR }}][${{ env.TF_WORKSPACE }}] Terraform Plan 📖 \`${{ steps.plan-prod.outcome }}\`
119+
<details><summary>Show Plan</summary>
120+
\`\`\`\n
121+
${process.env.PLAN}
122+
\`\`\`
123+
</details>
124+
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
125+
github.issues.createComment({
126+
issue_number: context.issue.number,
127+
owner: context.repo.owner,
128+
repo: context.repo.repo,
129+
body: output
130+
})
131+
- name: Terraform Plan Stage Status
132+
if: steps.plan-stage.outcome == 'failure'
133+
run: exit 1
134+
135+
- name: Terraform Plan Prod Status
136+
if: steps.plan-prod.outcome == 'failure'
137+
run: exit 1

Dockerfile

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,42 @@ 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+
1241

1342
USER ${USERNAME}
1443
RUN npm cache clean --force && npm install
@@ -37,12 +66,12 @@ RUN chown -R ${USERNAME}:${USERNAME} /var/cache/nginx && \
3766
chown -R ${USERNAME}:${USERNAME} /etc/nginx/conf.d
3867
RUN touch /var/run/nginx.pid && chown -R ${USERNAME}:${USERNAME} /var/run/nginx.pid
3968

40-
# FIXME: Actually if we can deploy to azure in port 80 we need a root user
41-
# Maybe we can refactor this dockerfile to use root user directly this is not a good approach y
42-
# security terms. It's a good practice to have rootless in containers so for this
43-
# we can to refactor this dockerfile and the terraform module to deploy in other ports because
69+
# FIXME: Actually if we can deploy to azure in port 80 we need a root user
70+
# Maybe we can refactor this dockerfile to use root user directly this is not a good approach y
71+
# security terms. It's a good practice to have rootless in containers so for this
72+
# we can to refactor this dockerfile and the terraform module to deploy in other ports because
4473
# Ports below 1024 needs root permisions.
45-
74+
4675
# USER ${USERNAME}
4776

4877
EXPOSE 80

Makefile

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,14 @@ remove: ## Delete container timetracker_ui.
3939
docker-compose down --volumes --remove-orphans --rmi local
4040

4141
.PHONY: test
42-
test: ## Run all tests on docker container timetracker_ui.
43-
docker-compose --env-file ./.env up -d
44-
docker exec -it timetracker_ui bash -c "npm run test"
42+
test: ## Run all tests on docker container timetracker_ui at the CLI.
43+
docker-compose -f docker-compose.yml --env-file ./.env up -d
44+
docker exec timetracker_ui bash -c "npm run ci-test"
45+
46+
.PHONY: testdev
47+
testdev: ## Run all tests on docker container timetracker_ui at the Dev
48+
docker-compose -f docker-compose.yml -f docker-compose.dev.yml --env-file ./.env up -d
49+
docker exec timetracker_ui bash -c "npm run ci-test"
4550

4651
.PHONY: publish
4752
publish: require-acr-arg require-image_tag-arg ## Upload a docker image to the stage azure container registry acr=<name_of_the_azure_container_registry> image_tag=<tag_for_the_image>
@@ -66,13 +71,13 @@ remove_prod: ## Delete container timetracker_ui_prod.
6671
docker rm timetracker_ui_prod
6772

6873
.PHONY: publish_prod
69-
publish_prod: require-acr-arg require-image_tag-arg ## Upload a docker image to the prod azure container registry acr=<name_of_the_azure_container_registry> image_tag=<tag_for_the_image>
74+
publish_prod: ## Upload a docker image to the prod azure container registry acr=<name_of_the_azure_container_registry> image_tag=<tag_for_the_image>
7075
docker tag timetracker_ui_prod:latest $(acr).azurecr.io/timetracker_ui:$(image_tag)
7176
docker push $(acr).azurecr.io/timetracker_ui:$(image_tag)
7277

7378
.PHONY: login
7479
login: ## Login in respository of docker images.
75-
az acr login --name $(container_registry)
80+
az acr login --name $(acr)
7681

7782
.PHONY: release
7883
release: require-VERSION-arg require-COMMENT-arg ## Creates an pushes a new tag.

docker-compose.dev.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: '3.9'
2+
services:
3+
time-tracker-ui:
4+
user: root
5+
volumes:
6+
- ./src:/home/timetracker/time-tracker-ui/src/
7+
- ./scripts:/home/timetracker/time-tracker-ui/scripts/
8+
- ./e2e:/home/timetracker/time-tracker-ui/e2e/
9+
- ./coverage:/home/timetracker/time-tracker-ui/coverage
10+
- ./angular.json:/home/timetracker/time-tracker-ui/angular.json
11+
- ./karma.conf.js:/home/timetracker/time-tracker-ui/karma.conf.js
12+
- ./package.json:/home/timetracker/time-tracker-ui/package.json
13+
- ./webpack.config.js:/home/timetracker/time-tracker-ui/webpack.config.js

docker-compose.yml

Lines changed: 2 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,4 @@ 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+

0 commit comments

Comments
 (0)