Skip to content

Commit

Permalink
Merge pull request #56 from mihai-satmarean/feature/55-create-vpc-and…
Browse files Browse the repository at this point in the history
…-implement-ec2-into-local-branch

Feature/55 create vpc and implement ec2 into local branch
  • Loading branch information
BlackText authored Dec 7, 2024
2 parents b24b897 + e200eea commit 573c9b5
Show file tree
Hide file tree
Showing 30 changed files with 717 additions and 46 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/github-actions-demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@ jobs:
Explore-GitHub-Actions:
runs-on: ubuntu-latest
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_RADU }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_RADU }}
aws-region: eu-central-1
- name: Deploy Infrastructure
run: |
aws s3 ls
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🎉 The job was automatically triggered by a ${{ secrets.AWS_ACCESS_KEY_ID_RADU }} & ${{ secrets.AWS_SECRET_ACCESS_KEY_RADU }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
Expand All @@ -16,3 +26,19 @@ jobs:
run: |
ls ${{ github.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."
Explore-GitHub-Actions-Radu:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server ${{ runner.arch }} hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v4
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."


23 changes: 23 additions & 0 deletions .github/workflows/terraform-apply.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Terraform apply
run-name: ${{ github.actor }} is deploying on AWS 🚀
on:
push:
branches:
- 55-create-vpc-and-implement-ec2-into-local-branch
jobs:
Deploy-AWS-EC2:
runs-on: ubuntu-latest
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_RADU }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_RADU }}
aws-region: eu-central-1
- name: Checkout Repository
uses: actions/checkout@v4
- name: Deploy Infrastructure
run: |
cd terraform/terraform-modules/tf-ec2-module/
terraform init
terraform destroy -auto-approve
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.box
40 changes: 40 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Project Title

A short description of your project, what it does, and why it's useful.

---

## Table of Contents

- [About](#about)
- [Installation](#installation)
- [Usage](#usage)
- [Contributing](#contributing)
- [License](#license)
- [Contact](#contact)

---

## About

Provide a more detailed description of your project here. You can include:

- The main goal of the project
- Technologies used
- Key features
- Screenshots (if applicable)

---

## Installation

### Prerequisites

- List any software or tools required to run the project (e.g., Node.js, Python, etc.)

### Steps

1. Clone the repository
```bash
git clone https://github.com/your-username/project-name.git

16 changes: 16 additions & 0 deletions ansible/python.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
- name: Start Python web server
hosts: all
become: yes
tasks:
- name: Ensure Python is installed
apt:
name: python3
state: present

- name: Start Python web server
command: python3 -m http.server
args:
chdir: /var/www/html
async: 3600
poll: 0
6 changes: 6 additions & 0 deletions ansible/roles/nginx/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Restart NGINX
systemd:
name: nginx
state: restarted
become: true
34 changes: 34 additions & 0 deletions ansible/roles/nginx/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
- name: Install NGINX
apt:
name: nginx
state: present
update_cache: yes
become: true

- name: Create NGINX configuration
template:
src: nginx.conf.j2
dest: /etc/nginx/nginx.conf
owner: root
group: root
mode: '0644'
notify: Restart NGINX
become: true

- name: Create load balancer configuration
template:
src: load-balancer.conf.j2
dest: /etc/nginx/conf.d/load-balancer.conf
owner: root
group: root
mode: '0644'
notify: Restart NGINX
become: true

- name: Ensure NGINX service is running
systemd:
name: nginx
state: started
enabled: yes
become: true
16 changes: 16 additions & 0 deletions ansible/roles/nginx/templates/load-balancer.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
upstream backend {
{% for server in backend_servers %}
server {{ server.host }}:{{ server.port }} weight={{ server.weight | default(1) }};
{% endfor %}
}

server {
listen 80;
server_name {{ server_name }};

location / {
proxy_pass http://backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
26 changes: 26 additions & 0 deletions ansible/roles/nginx/templates/nginx.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
worker_connections 768;
}

http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;

include /etc/nginx/mime.types;
default_type application/octet-stream;

ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

include /etc/nginx/conf.d/*.conf;
}
9 changes: 9 additions & 0 deletions ansible/roles/nginx/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
server_name: example.com
backend_servers:
- host: 192.168.1.10
port: 8080
weight: 3
- host: 192.168.1.11
port: 8080
weight: 2
90 changes: 45 additions & 45 deletions ci-cd/README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
# sciitdevops

## Project Overview
This repository serves as the base for the DevOps training program. It is designed to help participants advance towards the final goal of deploying a web site/app using all the tooling and practices covered in the DevOps training.

## How to Use This Repository

### Branching Strategy
- Each participant is encouraged to create their own branch from the main branch.
- Use your branch to work on exercises, projects, and any custom implementations related to the training.
- Regularly merge changes from the main branch to keep your branch up to date.

### Repository Structure
- The repository will contain specific folders for different exercises and projects.
- **Terraform Code:** Store Terraform scripts for managing AWS and Azure resources in the `terraform/` directory.
- **CI/CD Configuration:** Store Jenkins, GitHub Actions, or other CI/CD configuration files in the `ci-cd/` directory.
- **Application Code:** Store the web application code in the `app/` directory.
- **Documentation:** Use the `docs/` directory for any additional documentation or notes.

## Getting Started
1. **Clone the Repository:**
```bash
git clone [email protected]:mihai-satmarean/sciitdevops.git
```

2. **Create a Branch:**
```bash
git checkout -b your-branch-name
```

3. **Work on Exercises and Projects:**
- Use the provided directories to organize your work.
- Commit and push your changes regularly.

4. **Collaborate and Review:**
- Collaborate with other participants by reviewing and discussing each other's work.
- Use pull requests to propose changes to the main branch.

## Final Goal
The final goal of this training is to deploy a fully functional web site/app using the DevOps tools and practices learned throughout the course. This includes:
- Infrastructure provisioning with Terraform
- CI/CD pipelines with Jenkins or GitHub Actions
- Application deployment and monitoring

By following this structure and utilizing the repository, participants will gain hands-on experience and work towards achieving the final goal of the training.













































1 change: 0 additions & 1 deletion docs/ansible_guide.md

This file was deleted.

4 changes: 4 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "aws_s3_bucket" "bucket" {
bucket = var.bucket_name
acl = var.acl
}
4 changes: 4 additions & 0 deletions s3_module.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "aws_s3_bucket" "bucket" {
bucket = var.bucket_name
acl = var.acl
}
21 changes: 21 additions & 0 deletions terraform/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
TERRAFORM AWS S3 BUCKETS MODULE

To keep our work well structured, ww will use separate folders for each type of resource. In our case, for modules we will use "terraform-modules".

The structure of this project is:
Main folder - terraform
Subfolder - terraform-modules
Subfolder - tf-s3-module

In the "terraform" folder we have 2 files:
1. readme.md - this is the file that contains valuable information about the project
2. s3.tf - this is the file that we will use to create our AWS S3 buckets. In this file we need to change the "name" and "owner" vars to our desire.
Also, we can specify more variables (ex. acl, force_destroy, etc) or use the default ones in the module folder.

In the "terraform-modules" folder we will create separate folders for each module. The first one is the AWS S3 Module, "tf-s3-module", that contains
the code for a module that we will use to manage the AWS S3 buckets in an easy and organized way, using variables. The folder contains 4 files:
1. inputs.tf - this file contains the variables we can use with our module
2. outputs.tf - this file contains the output variables we need from the job execution output
3. versions.tf - this file contains the module version as well as the minimum required version (using an older version may lead to errors as variables may not be implemented, etc.)
4. main.tf - this is the main module file

11 changes: 11 additions & 0 deletions terraform/s3.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module "s3_bucket" {
source = "git::https://github.com/mihai-satmarean/sciitdevops/blob/main/terraform/terraform-modules/tf-s3-modules/" # se va modifica in functie de locatia modulului in GitHub

name = "nume" # numele tag-ului ce il atribuim resursei
owner = "owner" # numele owner-ului resursei

s3_bucket_names = ["mariusb_devops_bucket1"]
acl = "private"
force_destroy = false

}
26 changes: 26 additions & 0 deletions terraform/terraform-modules/tf-ec2-module/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Local .terraform directories
**/.terraform/*

# Ignore variables files
*.auto.tfvars

# Ignore override files
*.tfoverride

# Ignore environment-specific files
.envrc

# Ignore CLI configuration files
.terraformrc
terraform.rc

# Ignore Terraform state files and providers
terraform.tfstate
terraform.lock.hcl

# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*
Loading

0 comments on commit 573c9b5

Please sign in to comment.