Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslawCzerwinski authored and JaroslawCzerwinski committed Sep 19, 2023
0 parents commit f1020d7
Show file tree
Hide file tree
Showing 55 changed files with 1,463 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/deploy-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Deploy on dev
on:
workflow_dispatch:
inputs:
version:
description: 'App version to deploy'
required: true
default: '1.0.0'

env:
ENVIRONMENT: dev
REGION: eu-central-1
TEAM: Platform-Engineering

jobs:
release:
name: Deploy workoutrecorder-frontend
runs-on: [self-hosted, dev]
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Pull SSH key for Ansible connection
run: |
cd ansible
aws s3 cp \
s3://red-devops-workout-recorder/post-provisioning/app_${{ env.ENVIRONMENT }}_key.pem \
app_${{ env.ENVIRONMENT }}_key.pem
chmod 600 app_${{ env.ENVIRONMENT }}_key.pem
- name: Download artifact
run: |
cd ansible
aws s3 cp \
s3://red-devops-workout-recorder/release/workoutrecorder-frontend-${{ github.event.inputs.version }}.zip \
workoutrecorder-frontend-${{ github.event.inputs.version }}.zip
- name: Ansible Playbook
run: |
cd ansible
ansible-playbook \
deploy.yaml \
-i ./inventories/${{ env.ENVIRONMENT }}/inventory_aws_ec2.yaml \
-extra-vars="app_version=${{ github.event.inputs.version }}" \
--private-key app_${{ env.ENVIRONMENT }}_key.pem
- name: Remove SSH key
if: always()
run: |
cd ansible
rm app_${{ env.ENVIRONMENT }}_key.pem -f
continue-on-error: true
52 changes: 52 additions & 0 deletions .github/workflows/deploy-prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Deploy on prod
on:
workflow_dispatch:
inputs:
version:
description: 'App version to deploy'
required: true
default: '1.0.0'

env:
ENVIRONMENT: prod
REGION: eu-central-1
TEAM: Platform-Engineering

jobs:
release:
name: Deploy workoutrecorder-frontend
runs-on: [self-hosted, prod]
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Pull SSH key for Ansible connection
run: |
cd ansible
aws s3 cp \
s3://red-devops-workout-recorder/post-provisioning/app_${{ env.ENVIRONMENT }}_key.pem \
app_${{ env.ENVIRONMENT }}_key.pem
chmod 600 app_${{ env.ENVIRONMENT }}_key.pem
- name: Download artifact
run: |
cd ansible
aws s3 cp \
s3://red-devops-workout-recorder/release/workoutrecorder-frontend-${{ github.event.inputs.version }}.zip \
workoutrecorder-frontend-${{ github.event.inputs.version }}.zip
- name: Ansible Playbook
run: |
cd ansible
ansible-playbook \
deploy.yaml \
-i ./inventories/${{ env.ENVIRONMENT }}/inventory_aws_ec2.yaml \
-extra-vars="app_version=${{ github.event.inputs.version }}" \
--private-key app_${{ env.ENVIRONMENT }}_key.pem
- name: Remove SSH key
if: always()
run: |
cd ansible
rm app_${{ env.ENVIRONMENT }}_key.pem -f
continue-on-error: true
52 changes: 52 additions & 0 deletions .github/workflows/deploy-uat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Deploy on uat
on:
workflow_dispatch:
inputs:
version:
description: 'App version to deploy'
required: true
default: '1.0.0'

env:
ENVIRONMENT: uat
REGION: eu-central-1
TEAM: Platform-Engineering

jobs:
release:
name: Deploy workoutrecorder-frontend
runs-on: [self-hosted, uat]
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Pull SSH key for Ansible connection
run: |
cd ansible
aws s3 cp \
s3://red-devops-workout-recorder/post-provisioning/app_${{ env.ENVIRONMENT }}_key.pem \
app_${{ env.ENVIRONMENT }}_key.pem
chmod 600 app_${{ env.ENVIRONMENT }}_key.pem
- name: Download artifact
run: |
cd ansible
aws s3 cp \
s3://red-devops-workout-recorder/release/workoutrecorder-frontend-${{ github.event.inputs.version }}.zip \
workoutrecorder-frontend-${{ github.event.inputs.version }}.zip
- name: Ansible Playbook
run: |
cd ansible
ansible-playbook \
deploy.yaml \
-i ./inventories/${{ env.ENVIRONMENT }}/inventory_aws_ec2.yaml \
-extra-vars="app_version=${{ github.event.inputs.version }}" \
--private-key app_${{ env.ENVIRONMENT }}_key.pem
- name: Remove SSH key
if: always()
run: |
cd ansible
rm app_${{ env.ENVIRONMENT }}_key.pem -f
continue-on-error: true
52 changes: 52 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Release workoutrecorder-frontend
on:
workflow_dispatch:
inputs:
version:
description: 'App version to release'
required: true
default: '1.0.0'
fabioip:
description: 'Public fabio ip addres'
required: true

jobs:
release:
name: Release workoutrecorder-frontend
runs-on: self-hosted
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v2

- name: Set app version
run: |
version=${{ github.event.inputs.version }}
sed -i "s/<VERSION>/$version/g" frontend/package.json
- name: Set fabio public ip
run: |
fabioip=${{ github.event.inputs.fabioip }}
sed -i "s/<FABIO_PUBLIC_IP>/$fabioip/g" frontend/src/environments/environment.prod.ts
- name: Install dependency
run: |
mkdir app
cp frontend/package.json app
cd app
npm install
- name: Build and Package
run: |
cp frontend/* app -r
cd app
npm run build --prod
zip -jr workoutrecorder-frontend-${{ github.event.inputs.version }}.zip dist/workoutrecorder-front/*
- name: Upload Release
run: |
aws s3 cp \
app/workoutrecorder-frontend-${{ github.event.inputs.version }}.zip \
s3://red-devops-workout-recorder/release/workoutrecorder-frontend-${{ github.event.inputs.version }}.zip
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Red-DevOps

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Workoutrecorder - Frontend App

The content of this project is part of the post on blog https://red-devops.pl/ <br>
The repository consists of two parts. The first part contained in the frontend folder contains the source code of the Angular application. The second part of the application, contained in the ansibl folder, contains the Ansible playbook that deploys applications to remote servers. This repository is part of a larger workout-recorder project which can be found here https://github.com/red-devops/Workout-recorder-consul. The application should be deployed on hoset after executing the HashiCorp Terraform from folder 100-app-infra/180-instances from the main repo.
4 changes: 4 additions & 0 deletions ansible/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[defaults]
remote_user = ubuntu
host_key_checking = False
enable_plugins = host_list, virtualbox, yaml, constructed, aws_ec2, script, ini, auto, toml
17 changes: 17 additions & 0 deletions ansible/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
- name: Deploy workoutrecorder backend
hosts: all
become: true
roles:

- role: prerequisites
tags:
- prerequisites

- role: consul
tags:
- consul

- role: frontend
tags:
- frontend
19 changes: 19 additions & 0 deletions ansible/group_vars/all.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#APP
app: "frontend"
user: frontend
group: frontend
mode: u+rwx,g+r,o+r
app_port: 80
app_home: "/home/{{ user }}"
app_data: "{{ app_home }}/data"
app_config_home: "{{ app_home }}/config"
app_bin_home: "{{ app_home }}/bin"
app_log_home: "{{ app_home }}/log"
app_version: 1.0.0
sites_available_dir: /etc/nginx/sites-available

#AWS
region: "eu-central-1"

#Consul
consul_bootstrap_secret_name: Consul-Global-Managemen-Token-{{ env }}
2 changes: 2 additions & 0 deletions ansible/inventories/dev/group_vars/all.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Dev environment
env: dev
2 changes: 2 additions & 0 deletions ansible/inventories/dev/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[all]
localhost ansible_connection=local
13 changes: 13 additions & 0 deletions ansible/inventories/dev/inventory_aws_ec2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
plugin: aws_ec2
regions:
- "eu-central-1"
filters:
instance-state-name: running
tag:Name: EC2-dev-frontend-ASG
tag:Environment: dev
tag:ostype: linux
compose:
private_ip_address: private_ip_address
hostnames:
- private-ip-address
2 changes: 2 additions & 0 deletions ansible/inventories/prod/group_vars/all.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Prod environment
env: prod
2 changes: 2 additions & 0 deletions ansible/inventories/prod/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[all]
localhost ansible_connection=local
13 changes: 13 additions & 0 deletions ansible/inventories/prod/inventory_aws_ec2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
plugin: aws_ec2
regions:
- "eu-central-1"
filters:
instance-state-name: running
tag:Name: EC2-prod-backend-ASG
tag:Environment: prod
tag:ostype: linux
compose:
private_ip_address: private_ip_address
hostnames:
- private-ip-address
2 changes: 2 additions & 0 deletions ansible/inventories/uat/group_vars/all.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Uat environment
env: uat
2 changes: 2 additions & 0 deletions ansible/inventories/uat/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[all]
localhost ansible_connection=local
13 changes: 13 additions & 0 deletions ansible/inventories/uat/inventory_aws_ec2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
plugin: aws_ec2
regions:
- "eu-central-1"
filters:
instance-state-name: running
tag:Name: EC2-uat-backend-ASG
tag:Environment: uat
tag:ostype: linux
compose:
private_ip_address: private_ip_address
hostnames:
- private-ip-address
2 changes: 2 additions & 0 deletions ansible/roles/consul/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# Defaults for consul agent
Loading

0 comments on commit f1020d7

Please sign in to comment.