-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker_project.yml
160 lines (142 loc) · 4.6 KB
/
docker_project.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
- name: install docker and config
hosts: _development
become: true
vars:
aws_region: us-east-1
ecr_registry: XXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com # your ecr repository
tasks:
- name: update all packages
ansible.builtin.yum:
name: '*'
state: latest
- name: Remove docker if installed from CentOS repo
ansible.builtin.yum:
name:
- docker
- docker-client
- docker-client-latest
- docker-common
- docker-latest
- docker-latest-logrotate
- docker-logrotate
- docker-engine
state: removed
- name: Install yum utils
ansible.builtin.yum:
name: "{{ item }}"
state: latest
with_items:
- yum-utils
- device-mapper-persistent-data
- lvm2
- unzip
- name: Add Docker repo
ansible.builtin.get_url:
url: https://download.docker.com/linux/centos/docker-ce.repo
dest: /etc/yum.repos.d/docker-ce.repo
- name: Install Docker
ansible.builtin.package:
name: docker-ce
state: latest
- name: Add user ec2-user to docker group
ansible.builtin.user:
name: ec2-user
groups: docker
append: yes
- name: Start Docker service
ansible.builtin.service:
name: docker
state: started
enabled: yes
- name: install aws cli
ansible.builtin.get_url:
url: https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip
dest: /home/ec2-user/awscliv2.zip
- name: unzip zip file
ansible.builtin.unarchive:
src: /home/ec2-user/awscliv2.zip
dest: /home/ec2-user
remote_src: True
- name: run the installer
ansible.builtin.command:
args:
cmd: "./aws/install"
creates: /usr/local/bin/aws
- name: log in to AWS ec2-user
ansible.builtin.shell: |
export PATH=/usr/local/bin:$PATH
aws ecr get-login-password --region {{ aws_region }} | docker login --username AWS --password-stdin {{ ecr_registry }}
# source "~/.bash_profile" #####
- name: postgre database config
hosts: _ansible_postgresql
become: true
vars:
container_name: gibran_postgre
image_name: XXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/gibran-repo/study-project-jenkins:postgre # your ecr repository
tasks:
- name: remove postgre container
community.docker.docker_container:
name: "{{ container_name }}"
state: absent
force_kill: true
- name: remove postgre image
community.docker.docker_image:
name: "{{ image_name }}"
state: absent
- name: Launch postgresql docker container
community.docker.docker_container:
name: "{{ container_name }}"
image: "{{ image_name }}"
state: started
ports:
- "5432:5432"
env:
POSTGRES_PASSWORD: "xxxxxxx" #your password
volumes:
- /db-data:/var/lib/postgresql/data
- name: Nodejs Server configuration
hosts: _ansible_nodejs
become: true
vars:
container_name: gibran_nodejs
image_name: XXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/gibran-repo/study-project-jenkins:nodejs # your ecr repository
tasks:
- name: remove postgre container
community.docker.docker_container:
name: "{{ container_name }}"
state: absent
force_kill: true
- name: remove postgre image
community.docker.docker_image:
name: "{{ image_name }}"
state: absent
- name: Launch postgresql docker container
community.docker.docker_container:
name: "{{ container_name }}"
image: "{{ image_name }}"
state: started
ports:
- "5000:5000"
- name: React UI Server configuration
hosts: _ansible_react
become: true
vars:
container_name: gibran_react
image_name: XXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/gibran-repo/study-project-jenkins:react # your ecr repository
tasks:
- name: remove postgre container
community.docker.docker_container:
name: "{{ container_name }}"
state: absent
force_kill: true
- name: remove postgre image
community.docker.docker_image:
name: "{{ image_name }}"
state: absent
- name: Launch react docker container
community.docker.docker_container:
name: "{{ container_name }}"
image: "{{ image_name }}"
state: started
ports:
- "3000:3000"