File tree 6 files changed +44
-6
lines changed
6 files changed +44
-6
lines changed Original file line number Diff line number Diff line change @@ -40,4 +40,7 @@ terraform.rc
40
40
credentials.json
41
41
42
42
# ssh
43
- .ssh /
43
+ .ssh /
44
+
45
+ # env
46
+ .env
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ GREEN = $(shell tput -Txterm setab 2 && tput -Txterm setaf 0)
3
3
PURPLE = $(shell tput -Txterm setab 5 && tput -Txterm setaf 7)
4
4
RESET = $(shell tput -Txterm sgr0)
5
5
6
+ VAR_FILE = terraform.prod.tfvars
7
+
6
8
all : create
7
9
8
10
create : create-compute-engine
@@ -19,7 +21,7 @@ create-compute-engine:
19
21
@echo " "
20
22
@echo " $( GREEN) Terraform compute engine init $( RESET) "
21
23
@cd src && terraform init
22
- @cd src && terraform apply -auto-approve
24
+ @cd src && terraform apply -auto-approve -var-file= $( VAR_FILE )
23
25
24
26
destroy-s3 :
25
27
@echo " "
Original file line number Diff line number Diff line change @@ -56,6 +56,9 @@ module "training_worker" {
56
56
gpu_type = var. gpu_type
57
57
zone = var. zone
58
58
username = var. username
59
+ env_file = var. env_file
60
+ dockerhub_id = var. dockerhub_id
61
+ dockerhub_pwd = var. dockerhub_pwd
59
62
60
63
depends_on = [ module . vpc_network ]
61
64
}
Original file line number Diff line number Diff line change @@ -51,7 +51,6 @@ resource "google_compute_instance" "gpu_instance" {
51
51
service_account {
52
52
scopes = [ " https://www.googleapis.com/auth/devstorage.read_write" ]
53
53
}
54
-
55
54
provisioner "file" {
56
55
// We use a provisioner to copy our local ssh key inside the worker. This will be used to authenticate with GitHub.
57
56
source = var. ssh_file_private
@@ -66,6 +65,20 @@ resource "google_compute_instance" "gpu_instance" {
66
65
}
67
66
}
68
67
68
+ provisioner "file" {
69
+ // We use a provisioner to copy our local ssh key inside the worker. This will be used to authenticate with GitHub.
70
+ source = var. env_file
71
+ destination = " /home/${ var . username } /.env"
72
+
73
+ connection {
74
+ type = " ssh"
75
+ user = var. username
76
+ port = 22
77
+ private_key = " ${ file (var. ssh_file_private )} "
78
+ host = google_compute_instance. gpu_instance . network_interface [0 ]. access_config [0 ]. nat_ip
79
+ }
80
+ }
81
+
69
82
provisioner "remote-exec" {
70
83
// Here we define some init steps we want to run when our instance is created
71
84
inline = [
@@ -88,7 +101,8 @@ resource "google_compute_instance" "gpu_instance" {
88
101
" sudo apt update" ,
89
102
" sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin" ,
90
103
" sudo systemctl start docker" ,
91
- " sudo systemctl enable docker"
104
+ " sudo systemctl enable docker" ,
105
+ " echo ${ var . dockerhub_pwd } | docker login -u ${ var . dockerhub_pwd } --password-stdin" # dockerhub login
92
106
]
93
107
connection {
94
108
type = " ssh"
Original file line number Diff line number Diff line change @@ -12,4 +12,10 @@ variable "gpu_type" {}
12
12
13
13
variable "zone" {}
14
14
15
- variable "username" {}
15
+ variable "username" {}
16
+
17
+ variable "env_file" {}
18
+
19
+ variable "dockerhub_id" {}
20
+
21
+ variable "dockerhub_pwd" {}
Original file line number Diff line number Diff line change @@ -10,6 +10,12 @@ variable "ssh_file_private" {
10
10
default = " ../.ssh/id_ed25519"
11
11
}
12
12
13
+ variable "env_file" {
14
+ description = " env file path"
15
+ type = string
16
+ default = " ../.env"
17
+ }
18
+
13
19
variable "git_ssh_url" {
14
20
description = " git clone url"
15
21
type = string
@@ -68,4 +74,8 @@ variable "username" {
68
74
description = " my google email id"
69
75
type = string
70
76
default = " sangyleegcp1"
71
- }
77
+ }
78
+
79
+ variable "dockerhub_id" {}
80
+
81
+ variable "dockerhub_pwd" {}
You can’t perform that action at this time.
0 commit comments