Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
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
4 changes: 3 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.dev.env filter=git-crypt diff=git-crypt
.prod.env filter=git-crypt-PROD diff=git-crypt-PROD
.stage.env filter=git-crypt-STAGE diff=git-crypt-STAGE
.stage.env filter=git-crypt-STAGE diff=git-crypt-STAGE
.stage.aws.env filter=git-crypt-STAGE diff=git-crypt-STAGE
.prod.aws.env filter=git-crypt-PROD diff=git-crypt-PROD
65 changes: 65 additions & 0 deletions .github/workflows/aws-ui-cd-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: time-tracker-ui-cd-prod

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

jobs:
cd:
runs-on: ubuntu-latest
env:
AWS_ACCESS_KEY_ID: ${{secrets.AWS_ACCESS_KEY_ID}}
AWS_SECRET_ACCESS_KEY: ${{secrets.AWS_SECRET_ACCESS_KEY}}

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: Unlock PROD secrets
uses: sliteteam/[email protected]
env:
GIT_CRYPT_KEY: ${{ secrets.GIT_CRYPT_KEY_PROD }}

- name: Build the docker image
run: |-
docker build \
--target production -t timetracker_ui -f Dockerfile_prod \
.

- name: Publish docker image to prod aws container registry
run: |
make login publish_prod image_tag=$RELEASE_VERSION

- name: SCP files via ssh key
uses: appleboy/scp-action@master
env:
USERNAME: ${{ secrets.AWS_EC2_USER }}
HOST: ${{ secrets.PROD_UI_URL }}
KEY: ${{ secrets.PROD_AWS_PRIVATE_KEY }}
with:
source: './infrastructure/aws_ec2.sh'
target: '.'

- name: SCP files via ssh key - .prod.aws.env
uses: appleboy/scp-action@master
env:
USERNAME: ${{ secrets.AWS_EC2_USER }}
HOST: ${{ secrets.PROD_UI_URL }}
KEY: ${{ secrets.PROD_AWS_PRIVATE_KEY }}
with:
source: '.prod.aws.env'
target: '.'

- name: Deploy
run: |
TEMP=$(mktemp)
echo "${{ secrets.PROD_AWS_PRIVATE_KEY }}" > $TEMP
chmod 400 $TEMP
ssh -o 'StrictHostKeyChecking no' -i $TEMP ${{ secrets.AWS_EC2_USER }}@${{ secrets.PROD_UI_URL }} "chmod +x ./infrastructure/aws_ec2.sh"
ssh -o 'StrictHostKeyChecking no' -i $TEMP ${{ secrets.AWS_EC2_USER }}@${{ secrets.PROD_UI_URL }} "./infrastructure/aws_ec2.sh $RELEASE_VERSION" prod
67 changes: 67 additions & 0 deletions .github/workflows/aws-ui-cd-stage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: time-tracker-ui-cd-stage

on:
release:
types:
- published

jobs:
cd:
runs-on: ubuntu-latest
env:
TF_WORKSPACE: stage
AWS_ACCESS_KEY_ID: ${{secrets.AWS_ACCESS_KEY_ID}}
AWS_SECRET_ACCESS_KEY: ${{secrets.AWS_SECRET_ACCESS_KEY}}

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: Unlock STAGE secrets
uses: sliteteam/[email protected]
env:
GIT_CRYPT_KEY: ${{ secrets.GIT_CRYPT_KEY_STAGE }}

- name: Build the docker image
run: |-
docker build \
--target production -t timetracker_ui -f Dockerfile_stage \
.

- name: Publish docker image to stage AWS container registry
run: |
make login publish image_tag=$RELEASE_VERSION

- name: SCP files via ssh key - script
uses: appleboy/scp-action@master
env:
USERNAME: ${{ secrets.AWS_EC2_USER }}
HOST: ${{ secrets.STAGE_UI_URL }}
KEY: ${{ secrets.STAGE_AWS_PRIVATE_KEY }}
with:
source: './infrastructure/aws_ec2.sh'
target: '.'

- name: SCP files via ssh key - .stage.aws.env
uses: appleboy/scp-action@master
env:
USERNAME: ${{ secrets.AWS_EC2_USER }}
HOST: ${{ secrets.STAGE_UI_URL }}
KEY: ${{ secrets.STAGE_AWS_PRIVATE_KEY }}
with:
source: '.stage.aws.env'
target: '.'

- name: Deploy
run: |
TEMP=$(mktemp)
echo "${{ secrets.STAGE_AWS_PRIVATE_KEY }}" > $TEMP
chmod 400 $TEMP
ssh -o 'StrictHostKeyChecking no' -i $TEMP ${{ secrets.AWS_EC2_USER }}@${{ secrets.STAGE_UI_URL }} "chmod +x ./infrastructure/aws_ec2.sh"
ssh -o 'StrictHostKeyChecking no' -i $TEMP ${{ secrets.AWS_EC2_USER }}@${{ secrets.STAGE_UI_URL }} "./infrastructure/aws_ec2.sh $RELEASE_VERSION" stage
4 changes: 1 addition & 3 deletions .github/workflows/time-tracker-ui-cd-prod.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: time-tracker-ui-cd-prod

on:
release:
types:
- published
workflow_dispatch # deactivate workflow and run it manually only

jobs:
cd:
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/time-tracker-ui-cd-stage.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: time-tracker-ui-cd-stage

on:
push:
tags:
- 'v*.*.*'
workflow_dispatch # deactivate workflow and run it manually only

jobs:
cd:
Expand Down
Binary file added .prod.aws.env
Binary file not shown.
Binary file added .stage.aws.env
Binary file not shown.
Binary file modified .stage.env
Binary file not shown.
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ testdev: ## Run all tests on docker container timetracker_ui at the Dev
docker exec timetracker_ui bash -c "npm run ci-test"

.PHONY: publish
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>
docker tag timetracker_ui:latest $(acr).azurecr.io/timetracker_ui:$(image_tag)
docker push $(acr).azurecr.io/timetracker_ui:$(image_tag)
publish: require-image_tag-arg ## Upload a docker image to the stage AWS container registry image_tag=<tag_for_the_image>
docker tag timetracker_ui:latest 568748651446.dkr.ecr.us-east-1.amazonaws.com/time-tracker/stage-ui:$(image_tag)
docker push 568748651446.dkr.ecr.us-east-1.amazonaws.com/time-tracker/stage-ui:$(image_tag)

.PHONY: build_prod
build_prod: ## Create docker image with dependencies needed for production -- to test locally only
Expand Down Expand Up @@ -80,13 +80,13 @@ remove_prod: ## Delete container timetracker_ui_prod.
docker rm timetracker_ui_prod

.PHONY: publish_prod
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>
docker tag timetracker_ui_prod:latest $(acr).azurecr.io/timetracker_ui:$(image_tag)
docker push $(acr).azurecr.io/timetracker_ui:$(image_tag)
publish_prod: require-image_tag-arg ## Upload a docker image to the prod AWS container registry image_tag=<tag_for_the_image>
docker tag timetracker_ui:latest 568748651446.dkr.ecr.us-east-1.amazonaws.com/time-tracker/prod-ui:$(image_tag)
docker push 568748651446.dkr.ecr.us-east-1.amazonaws.com/time-tracker/prod-ui:$(image_tag)

.PHONY: login
login: ## Login in respository of docker images
az acr login --name $(acr)
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 568748651446.dkr.ecr.us-east-1.amazonaws.com

.PHONY: release
release: require-VERSION-arg require-COMMENT-arg ## Creates an pushes a new tag.
Expand Down
6 changes: 6 additions & 0 deletions infrastructure/aws_ec2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/sh
echo "Deploying $1..."
docker ps -aq | xargs docker stop| xargs docker rm --force --volumes
docker system prune -af
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 568748651446.dkr.ecr.us-east-1.amazonaws.com
docker run -d --name timetracker_ui --env-file .$2.aws.env -p 80:80 568748651446.dkr.ecr.us-east-1.amazonaws.com/time-tracker/$2-ui:$1
6 changes: 3 additions & 3 deletions src/app/modules/time-clock/services/entry.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ export class EntryService {

loadEntries(date): Observable<any> {
const timezoneOffset = new Date().getTimezoneOffset();
return this.http.get(`${this.baseUrl}?month=${date.month}&year=${date.year}&timezone_offset=${timezoneOffset}`);
return this.http.get(`${this.baseUrl}/?month=${date.month}&year=${date.year}&timezone_offset=${timezoneOffset}`);
}

createEntry(entryData): Observable<any> {
return this.http.post(this.baseUrl, entryData);
return this.http.post(`${this.baseUrl}/`, entryData);
}

updateEntry(entryData): Observable<any> {
Expand Down Expand Up @@ -64,7 +64,7 @@ export class EntryService {
findEntriesByProjectId(projectId: string): Observable<Entry[]> {
const startDate = this.getDateLastMonth();
const endDate = this.getCurrentDate();
const findEntriesByProjectURL = `${this.baseUrl}?limit=2&project_id=${projectId}&start_date=${startDate}&end_date=${endDate}`;
const findEntriesByProjectURL = `${this.baseUrl}/?limit=2&project_id=${projectId}&start_date=${startDate}&end_date=${endDate}`;
return this.http.get<Entry[]>(findEntriesByProjectURL);
}

Expand Down