Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
62d569b
feat: TT-509 Use terraform to provision ui infraestructure
jatobrun Mar 8, 2022
3fe4e5e
fix: TT-509 expose port 8080 in docker images
jatobrun Mar 10, 2022
6cc64e6
fix: TT-509 change app to port 80
jatobrun Mar 14, 2022
483cf6a
fix: TT-509 including empty line in all files
jatobrun Mar 15, 2022
a4b8426
fix: TT-509 Change the dockerfile to use root user and not app user
jatobrun Mar 16, 2022
da8e769
parent bf8977e79ef18ac85a09f9c55b213c72146c0de7
heikergil Mar 10, 2022
06735a0
fix: TT-513 tests cd-stage.yml
heikergil Mar 16, 2022
09235cf
feat: TT-513 CD - Prod yaml file
santii90ec Mar 16, 2022
d85bbe2
fix: TT-513 tests azure credentials
heikergil Mar 17, 2022
9cce0c9
fix: TT-513 change image tag variable
heikergil Mar 17, 2022
8b6fd37
fix: TT-513 add acr
heikergil Mar 17, 2022
81dae65
fix: TT-513 fix make publish
heikergil Mar 17, 2022
16671fe
fix: TT-513 fix make
heikergil Mar 17, 2022
0e496cc
fix: TT-513 change acr
heikergil Mar 17, 2022
cb9246a
feat: TT-513 cli test and dev test make file
santii90ec Mar 17, 2022
aebce8d
Merge branch 'TT-513-Create-CI/CD-pipeline-in-timer-tracker-ui-to-dep…
santii90ec Mar 17, 2022
b434d10
Merge branch 'TT-513-Create-CI/CD-pipeline-in-timer-tracker-ui-to-dep…
heikergil Mar 17, 2022
dd8f99d
TT-513 fix make publish command
heikergil Mar 17, 2022
fcd887c
fix: TT-513 change registry url
heikergil Mar 17, 2022
4a60730
fix: TT-513 fix registry url
heikergil Mar 17, 2022
15af506
fix: TT-513 test CI/CD pipeline
heikergil Mar 21, 2022
e5a3dd1
fix: TT-513 tests cd/ci make build
heikergil Mar 21, 2022
ab6e6fe
fix: TT-513 test tf init on ci/cd
heikergil Mar 21, 2022
2c6c80f
fix: TT-513 Fix CI on all PR
santii90ec Mar 21, 2022
275642d
fix: TT-513 Fix CI pipeline
santii90ec Mar 21, 2022
779e907
fix: TT-513 Fix Make file for dev testing
santii90ec Mar 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/time-tracker-ui-cd-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: time-tracker-ui-cd-prod

on:
release:
types:
- published

jobs:
cd:
runs-on: ubuntu-latest
env:
TF_WORKSPACE: prod
WORKING_DIR: infrastructure/
ARM_CLIENT_ID: ${{secrets.TF_ARM_CLIENT_ID}}
ARM_CLIENT_SECRET: ${{secrets.TF_ARM_CLIENT_SECRET}}
ARM_SUBSCRIPTION_ID: ${{secrets.TF_ARM_SUBSCRIPTION_ID}}
ARM_TENANT_ID: ${{secrets.TF_ARM_TENANT_ID}}

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Get the release_version
run: |
echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
echo $RELEASE_VERSION
- name: Login to azure
uses: Azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: Build the docker image
run: make build

- name: Publish docker image to prod azure container registry
run: |
make login publish acr=ADDAZUREPRDOREGISTRY image_tag=$RELEASE_VERSION
- name: Setup terraform
uses: hashicorp/setup-terraform@v1

- name: Authenticate with the TF modules repository
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.INFRA_TERRAFORM_MODULES_SSH_PRIV_KEY }}

- name: Terraform Init
working-directory: ${{ env.WORKING_DIR }}
run: terraform init

- name: Terraform Apply
working-directory: ${{ env.WORKING_DIR }}
run: terraform apply -lock=false -var-file="${{ env.TF_WORKSPACE }}.tfvars" -var "image_tag=$RELEASE_VERSION" -auto-approve
45 changes: 45 additions & 0 deletions .github/workflows/time-tracker-ui-cd-stage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: time-tracker-ui-cd-stage

on:
push:
tags:
- 'v*.*.*'

jobs:
cd:
runs-on: ubuntu-latest
env:
TF_WORKSPACE: stage
WORKING_DIR: infrastructure/
ARM_CLIENT_ID: ${{secrets.TF_ARM_CLIENT_ID}}
ARM_CLIENT_SECRET: ${{secrets.TF_ARM_CLIENT_SECRET}}
ARM_SUBSCRIPTION_ID: ${{secrets.TF_ARM_SUBSCRIPTION_ID}}
ARM_TENANT_ID: ${{secrets.TF_ARM_TENANT_ID}}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get the release_version
run: |
echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
echo $RELEASE_VERSION
- name: Login to azure
uses: Azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Build the docker image
run: make build
- name: Publish docker image to stage azure container registry
run: |
make login publish acr=tt513registry image_tag=$RELEASE_VERSION
- name: Setup terraform
uses: hashicorp/setup-terraform@v1
- name: Authenticate with the TF modules repository
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.INFRA_TERRAFORM_MODULES_SSH_PRIV_KEY }}
- name: Terraform Init
working-directory: ${{ env.WORKING_DIR }}
run: terraform init
- name: Terraform Apply
working-directory: ${{ env.WORKING_DIR }}
run: terraform apply -lock=false -var-file="${{ env.TF_WORKSPACE }}.tfvars" -var "image_tag=$RELEASE_VERSION" -auto-approve
146 changes: 146 additions & 0 deletions .github/workflows/time-tracker-ui-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
name: time-tracker-ui-ci

on:
push:
branches: [ main ]
pull_request:

jobs:
ci:
runs-on: ubuntu-latest
env:
WORKING_DIR: infrastructure/
DB_CONNECTION: ${{ secrets.DB_CONNECTION }}
ARM_CLIENT_ID: ${{secrets.TF_ARM_CLIENT_ID}}
ARM_CLIENT_SECRET: ${{secrets.TF_ARM_CLIENT_SECRET}}
ARM_SUBSCRIPTION_ID: ${{secrets.TF_ARM_SUBSCRIPTION_ID}}
ARM_TENANT_ID: ${{secrets.TF_ARM_TENANT_ID}}
strategy:
max-parallel: 5
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Authenticate with the TF modules repository
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.INFRA_TERRAFORM_MODULES_SSH_PRIV_KEY }}

# ci-test:
# name: Unit tests and CodeCoverage
# timeout-minutes: 90
# steps:
# - name: Set up Node.js version
# uses: actions/setup-node@v1
# with:
# node-version: '12.x'

# - name: Install dependencies
# run: npm install

- name: build docker
run: make build

- name: Inject Secrets
env:
SCOPES: ${{ secrets.SCOPES }}
CLIENT_ID: ${{ secrets.CLIENT_ID }}
AUTHORITY: ${{ secrets.AUTHORITY }}
STACK_EXCHANGE_ID: ${{ secrets.STACK_EXCHANGE_ID }}
STACK_EXCHANGE_ACCESS_TOKEN: ${{ secrets.STACK_EXCHANGE_ACCESS_TOKEN }}
AZURE_APP_CONFIGURATION_CONNECTION_STRING: ${{ secrets.AZURE_APP_CONFIGURATION_CONNECTION_STRING }}
run: |
chmod +x ./scripts/populate-keys.sh
sh ./scripts/populate-keys.sh

- name: Running tests
run: |
chmod -R 777 ./$home
make test
- name: Generate coverage report
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: bash <(curl -s https://codecov.io/bash)

- name: Setup terraform
uses: hashicorp/setup-terraform@v1

- name: 'Terraform Init'
id: init
working-directory: ./${{ env.WORKING_DIR }}
run: terraform init

- name: 'Terraform validate'
id: validate
working-directory: ./${{ env.WORKING_DIR }}
run: terraform validate

- name: Terraform Plan Stage
id: plan-stage
if: github.event_name == 'pull_request'
run: terraform plan -var-file=${{ env.TF_WORKSPACE }}.tfvars -var image_tag=latest -no-color
continue-on-error: true
working-directory: ./${{ env.WORKING_DIR }}
env:
TF_WORKSPACE: stage

- name: Terraform Plan Prod
id: plan-prod
if: github.event_name == 'pull_request'
run: terraform plan -var-file=${{ env.TF_WORKSPACE }}.tfvars -no-color
continue-on-error: true
working-directory: ./${{ env.WORKING_DIR }}
env:
TF_WORKSPACE: prod

- name: Update Pull Request with Stage Plan
uses: actions/[email protected]
if: github.event_name == 'pull_request'
env:
PLAN: "terraform\n${{ steps.plan-stage.outputs.stdout }}"
TF_WORKSPACE: stage
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### [${{ env.WORKING_DIR }}][${{ env.TF_WORKSPACE }}] Terraform Plan 📖 \`${{ steps.plan-stage.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`\n
${process.env.PLAN}
\`\`\`
</details>
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
- name: Update Pull Request with Prod Plan
uses: actions/[email protected]
if: github.event_name == 'pull_request'
env:
PLAN: "terraform\n${{ steps.plan-prod.outputs.stdout }}"
TF_WORKSPACE: prod
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### [${{ env.WORKING_DIR }}][${{ env.TF_WORKSPACE }}] Terraform Plan 📖 \`${{ steps.plan-prod.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`\n
${process.env.PLAN}
\`\`\`
</details>
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
- name: Terraform Plan Stage Status
if: steps.plan-stage.outcome == 'failure'
run: exit 1

- name: Terraform Plan Prod Status
if: steps.plan-prod.outcome == 'failure'
run: exit 1
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@ Thumbs.db

#ENV VARIABLES
.env

# Terraform files
**/.terraform**
34 changes: 32 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,43 @@ FROM node:14 AS development

ENV USERNAME timetracker
ENV HOME /home/${USERNAME}
ENV CHROME_BIN /opt/google/chrome/google-chrome
#Essential tools and xvfb
RUN apt-get update && apt-get install -y \
software-properties-common \
unzip \
curl \
wget \
xvfb

#Chrome browser to run the tests
ARG CHROME_VERSION=65.0.3325.181
RUN curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add \
&& wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
&& dpkg -i google-chrome-stable_current_amd64.deb || true
RUN apt-get install -y -f \
&& rm -rf /var/lib/apt/lists/*

#Disable the SUID sandbox so that chrome can launch without being in a privileged container
RUN dpkg-divert --add --rename --divert /opt/google/chrome/google-chrome.real /opt/google/chrome/google-chrome \
&& echo "#! /bin/bash\nexec /opt/google/chrome/google-chrome.real --no-sandbox --disable-setuid-sandbox \"\$@\"" > /opt/google/chrome/google-chrome \
&& chmod 755 /opt/google/chrome/google-chrome

#Chrome Driver
ARG CHROME_DRIVER_VERSION=2.37
RUN mkdir -p /opt/selenium \
&& curl http://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip -o /opt/selenium/chromedriver_linux64.zip \
&& cd /opt/selenium; unzip /opt/selenium/chromedriver_linux64.zip; rm -rf chromedriver_linux64.zip; ln -fs /opt/selenium/chromedriver /usr/local/bin/chromedriver;

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

WORKDIR ${HOME}/time-tracker-ui
COPY . .
RUN rm -f .env
RUN chown ${USERNAME}:${USERNAME} -R ${HOME}/time-tracker-ui
RUN chmod -R 777 ${HOME}/time-tracker-ui



USER ${USERNAME}
RUN npm cache clean --force && npm install
Expand Down Expand Up @@ -37,6 +67,6 @@ RUN chown -R ${USERNAME}:${USERNAME} /var/cache/nginx && \
chown -R ${USERNAME}:${USERNAME} /etc/nginx/conf.d
RUN touch /var/run/nginx.pid && chown -R ${USERNAME}:${USERNAME} /var/run/nginx.pid

USER ${USERNAME}
#USER ${USERNAME}

EXPOSE 4200
EXPOSE 80
27 changes: 16 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,39 @@ logs: ## Show logs of timetracker_ui.

.PHONY: stop
stop: ## Stop container timetracker_ui.
docker-compose stop
docker-compose stop

.PHONY: restart
restart: ## Restart container timetracker_ui.
docker-compose stop
docker-compose stop
docker-compose up -d

.PHONY: remove
remove: ## Delete container timetracker_ui.
docker-compose down --volumes --remove-orphans --rmi local

.PHONY: test
test: ## Run all tests on docker container timetracker_ui.
docker-compose --env-file ./.env up -d
docker exec -it timetracker_ui bash -c "npm run test"
test: ## Run all tests on docker container timetracker_ui at the CLI.
docker-compose -f docker-compose.yml --env-file ./.env up -d
docker exec timetracker_ui bash -c "npm run ci-test"

.PHONY: testdev
testdev: ## Run all tests on docker container timetracker_ui at the Dev
docker-compose -f docker-compose.yml -f docker-compose.dev.yml --env-file ./.env up -d
docker exec timetracker_ui bash -c "npm run ci-test"

.PHONY: publish
publish: ## Publish the container image timetracker_ui.
docker tag timetracker_ui:latest $(registry_url)/timetracker_ui:latest
docker push $(registry_url)/timetracker_ui:latest
docker tag timetracker_ui $(acr).azurecr.io/timetracker_ui:latest
docker push $(acr).azurecr.io/timetracker_ui:latest

.PHONY: build_prod
build_prod: ## Create docker image with dependencies needed for production.
docker build --target production -t timetracker_ui_prod -f Dockerfile .

.PHONY: run_prod
run_prod: ## Execute timetracker_ui_prod docker container.
docker run -d -p 4200:4200 --name timetracker_ui_prod timetracker_ui_prod
docker run -d -p 4200:4200 --name timetracker_ui_prod timetracker_ui_prod

.PHONY: remove_prod
remove_prod: ## Delete container timetracker_ui_pro.
Expand All @@ -63,9 +68,9 @@ remove_prod: ## Delete container timetracker_ui_pro.

.PHONY: publish_prod
publish_prod: ## Publish the container image timetracker_ui_prod.
docker tag timetracker_ui_prod:latest $(registry_url)/timetracker_ui_prod:latest
docker push $(registry_url)/timetracker_ui_prod:latest
docker tag timetracker_ui_prod:$(image_tag) $(registry_url)/timetracker_ui_prod:$(image_tag)
docker push $(registry_url)/timetracker_ui_prod:$(image_tag)

.PHONY: login
login: ## Login in respository of docker images.
az acr login --name $(container_registry)
az acr login --name $(acr)
13 changes: 13 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3.9'
services:
time-tracker-ui:
user: root
volumes:
- ./src:/home/timetracker/time-tracker-ui/src/
- ./scripts:/home/timetracker/time-tracker-ui/scripts/
- ./e2e:/home/timetracker/time-tracker-ui/e2e/
- ./coverage:/home/timetracker/time-tracker-ui/coverage
- ./angular.json:/home/timetracker/time-tracker-ui/angular.json
- ./karma.conf.js:/home/timetracker/time-tracker-ui/karma.conf.js
- ./package.json:/home/timetracker/time-tracker-ui/package.json
- ./webpack.config.js:/home/timetracker/time-tracker-ui/webpack.config.js
Loading