Compare commits

..
5 Commits
Author SHA1 Message Date
gregandev 72232d84a4 maj Dockerfile 2023-03-19 23:58:42 +01:00
gregandev 4b40fcf844 correction README.md + clean up app/deploy.sh 2023-03-19 23:56:29 +01:00
gregandev 820f540bdb correction README.md 2023-03-19 23:43:19 +01:00
gregandev ad84c675f4 correction README.md 2023-03-19 23:39:18 +01:00
gregandev 5aaf23e181 clean up 2023-03-19 23:36:16 +01:00
7 changed files with 43 additions and 54 deletions
+11 -5
View File
@@ -19,7 +19,7 @@ sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(l
sudo apt-get update && sudo apt-get install terraform
```
- Créer une paire de clé ssh dédiée pour Terraform
- Créer une paire de clé ssh dédiée pour Terraform dans ~/.ssh
```bash
# NOMMER LE CLE TERRAFORM
ssh-keygen -t rsa -b 4096
@@ -41,16 +41,17 @@ ssh-keygen -t rsa -b 4096
### TERRAFORM.TFVARS
- Modifier le fichier terraform.tfvars en fonction de votre environnement
- Modifier le fichier terraform.tfvars en fonction de votre environnement (gcp_project_id et gcp_auth_file)
## UTILISATION
- Lançer Terraform:
- Initialiser Terraform:
```bash
cd terraform-demo
terraform init
```
- Lançer Terraform:
- Dry run:
```bash
terraform plan
```
@@ -61,4 +62,9 @@ terraform apply
# Saisir yes quand demandé
```
> Visiter l'adresse fournie en output du terraform apply
> Visiter l'adresse fournie en output du terraform apply (Web-server-URL = "http://SERVER_IP:5000")
- Stopper Terraform:
```bash
terraform destroy
```
-8
View File
@@ -1,8 +0,0 @@
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_cloud():
return 'Hello Cloud!'
app.run(host='0.0.0.0')
-6
View File
@@ -1,13 +1,7 @@
FROM python:3.8-slim-bullseye
WORKDIR /python-docker
COPY ./requirements.txt requirements.txt
RUN python3 -m pip install -r requirements.txt
COPY ./ .
EXPOSE 5000
CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"]
+1 -4
View File
@@ -3,7 +3,4 @@
sudo apt-get update
sudo apt-get install -yq docker.io
sudo docker build --network=host -t flaskapp .
sudo docker run -d -p 5000:5000 flaskapp:latest
#python3 -m pip install flask
#python3 app.py >> log.txt 2>&1 &
#nohup python3 -u ./app.py > output.log &
sudo docker run -d -p 5000:5000 flaskapp:latest
+22 -22
View File
@@ -79,35 +79,35 @@ resource "google_compute_instance" "default" {
### COPY DES FICHIERS
provisioner "file" {
source = "app/"
destination = "./"
connection {
host = google_compute_instance.default.network_interface.0.access_config.0.nat_ip
type = "ssh"
user = var.gcp_ssh_user
timeout = "500s"
private_key = "${file(var.gcp_ssh_priv_key_file)}"
}
source = "app/"
destination = "./"
connection {
host = google_compute_instance.default.network_interface.0.access_config.0.nat_ip
type = "ssh"
user = var.gcp_ssh_user
timeout = "500s"
private_key = file(var.gcp_ssh_priv_key_file)
}
}
### START DEPLOY.SH
provisioner "remote-exec" {
inline = [
"chmod +x ~/deploy.sh",
"cd ~",
"./deploy.sh"
]
connection {
host = google_compute_instance.default.network_interface.0.access_config.0.nat_ip
type = "ssh"
user = var.gcp_ssh_user
timeout = "500s"
private_key = "${file(var.gcp_ssh_priv_key_file)}"
}
inline = [
"chmod +x ~/deploy.sh",
"cd ~",
"./deploy.sh"
]
connection {
host = google_compute_instance.default.network_interface.0.access_config.0.nat_ip
type = "ssh"
user = var.gcp_ssh_user
timeout = "500s"
private_key = file(var.gcp_ssh_priv_key_file)
}
}
}
## GET VM PUBLIC IP
output "Web-server-URL" {
value = join("",["http://",google_compute_instance.default.network_interface.0.access_config.0.nat_ip,":5000"])
value = join("", ["http://", google_compute_instance.default.network_interface.0.access_config.0.nat_ip, ":5000"])
}
+6 -6
View File
@@ -1,8 +1,8 @@
# GCP Settings
gcp_project_id = "terraform-demo-381114" # A MODIFIER
gcp_region = "europe-west9"
gcp_zone = "europe-west9-a"
gcp_auth_file = "./auth/terraform-demo-381114-158cfce10778.json" # A MODIFIER
gcp_ssh_user = "devops" # A MODIFIER OU PAS
gcp_ssh_pub_key_file = "~/.ssh/terraform.pub"
gcp_project_id = "terraform-demo-381114" # A MODIFIER
gcp_region = "europe-west9"
gcp_zone = "europe-west9-a"
gcp_auth_file = "./auth/terraform-demo-381114-158cfce10778.json" # A MODIFIER
gcp_ssh_user = "devops" # A MODIFIER OU PAS
gcp_ssh_pub_key_file = "~/.ssh/terraform.pub"
gcp_ssh_priv_key_file = "~/.ssh/terraform"
+3 -3
View File
@@ -24,15 +24,15 @@ variable "gcp_zone" {
variable "gcp_ssh_user" {
type = string
description = "SSH user"
description = "SSH user"
}
variable "gcp_ssh_pub_key_file" {
type = string
description = "SSH public key file path"
description = "SSH public key file path"
}
variable "gcp_ssh_priv_key_file" {
type = string
description = "SSH private key file path"
description = "SSH private key file path"
}