aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rwxr-xr-xjinwei.me/config/roles/wordpress/build.sh5
-rw-r--r--jinwei.me/config/roles/wordpress/defaults/main.yaml4
-rw-r--r--jinwei.me/config/roles/wordpress/tasks/main.yaml27
-rw-r--r--jinwei.me/config/roles/wordpress/templates/docker-compose.yaml.j219
-rw-r--r--jinwei.me/infra/cloudflare.tf6
-rw-r--r--jinwei.me/infra/rds.tf30
7 files changed, 72 insertions, 21 deletions
diff --git a/.gitignore b/.gitignore
index 4220221..86c0298 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,5 @@
1.idea/ 1.idea/
2aws-rc 2admin-rc
3connect_mysql.sh 3connect_mysql.sh
4# Local .terraform directories 4# Local .terraform directories
5**/.terraform/* 5**/.terraform/*
diff --git a/jinwei.me/config/roles/wordpress/build.sh b/jinwei.me/config/roles/wordpress/build.sh
new file mode 100755
index 0000000..55d7c0e
--- /dev/null
+++ b/jinwei.me/config/roles/wordpress/build.sh
@@ -0,0 +1,5 @@
1docker_repo=docker.io/clarkzjw
2docker_image=wordpress
3docker_image_tag=$(date -u +%Y%m%d)
4sudo docker build -t $docker_repo/$docker_image:"$docker_image_tag" .
5sudo docker push $docker_repo/$docker_image:"$docker_image_tag"
diff --git a/jinwei.me/config/roles/wordpress/defaults/main.yaml b/jinwei.me/config/roles/wordpress/defaults/main.yaml
new file mode 100644
index 0000000..250e0a5
--- /dev/null
+++ b/jinwei.me/config/roles/wordpress/defaults/main.yaml
@@ -0,0 +1,4 @@
1wordpress_image: clarkzjw/wordpress
2wordpress_image_tag: 20221211
3wordpress_port: 30080
4wordpress_home: /opt/wordpress
diff --git a/jinwei.me/config/roles/wordpress/tasks/main.yaml b/jinwei.me/config/roles/wordpress/tasks/main.yaml
index 51e1a2b..3835145 100644
--- a/jinwei.me/config/roles/wordpress/tasks/main.yaml
+++ b/jinwei.me/config/roles/wordpress/tasks/main.yaml
@@ -3,27 +3,14 @@
3 name: "{{ wordpress_image }}:{{ wordpress_image_tag }}" 3 name: "{{ wordpress_image }}:{{ wordpress_image_tag }}"
4 source: pull 4 source: pull
5 5
6- name: render config file
7 template:
8 src: docker-compose.yaml.j2
9 dest: "{{ wordpress_home }}/docker-compose.yaml"
10 mode: 0644
11
6- name: Start wordpress container using docker-compose 12- name: Start wordpress container using docker-compose
7 community.docker.docker_compose: 13 community.docker.docker_compose:
8 project_name: wordpress 14 project_name: wordpress
9 definition: 15 project_src: "{{ wordpress_home }}"
10 version: '3'
11 services:
12 cloudflared:
13 image: cloudflare/cloudflared
14 container_name: cloudflare-tunnel
15 restart: always
16 command: tunnel run
17 environment:
18 - TUNNEL_TOKEN={{ cloudflared_tunnel_token }}
19 wordpress:
20 image: "{{ wordpress_image }}:{{ wordpress_image_tag }}"
21 volumes:
22 - "{{ wordpress_home }}/wp-content:/var/www/html/wp-content"
23 restart: always
24 environment:
25 - WORDPRESS_DB_HOST={{ wordpress_db_host }}
26 - WORDPRESS_DB_USER={{ wordpress_db_user }}
27 - WORDPRESS_DB_PASSWORD={{ wordpress_db_password }}
28 - WORDPRESS_DB_NAME={{ wordpress_db_name }}
29 register: output 16 register: output
diff --git a/jinwei.me/config/roles/wordpress/templates/docker-compose.yaml.j2 b/jinwei.me/config/roles/wordpress/templates/docker-compose.yaml.j2
new file mode 100644
index 0000000..be85fb4
--- /dev/null
+++ b/jinwei.me/config/roles/wordpress/templates/docker-compose.yaml.j2
@@ -0,0 +1,19 @@
1version: '3'
2services:
3 cloudflared:
4 image: cloudflare/cloudflared
5 container_name: cloudflare-tunnel
6 restart: always
7 command: tunnel run
8 environment:
9 - TUNNEL_TOKEN={{ lookup('aws_ssm', '/jinwei-me/cloudflare/tunnel_token') }}
10 wordpress:
11 image: "{{ wordpress_image }}:{{ wordpress_image_tag }}"
12 volumes:
13 - "{{ wordpress_home }}/wp-content:/var/www/html/wp-content"
14 restart: always
15 environment:
16 - WORDPRESS_DB_HOST={{ lookup('aws_ssm', '/jinwei-me/mysql/host') }}:{{ lookup('aws_ssm', '/jinwei-me/mysql/port') }}
17 - WORDPRESS_DB_USER={{ lookup('aws_ssm', '/jinwei-me/mysql/username') }}
18 - WORDPRESS_DB_PASSWORD={{ lookup('aws_ssm', '/jinwei-me/mysql/password') }}
19 - WORDPRESS_DB_NAME={{ lookup('aws_ssm', '/jinwei-me/mysql/name') }}
diff --git a/jinwei.me/infra/cloudflare.tf b/jinwei.me/infra/cloudflare.tf
index 6e9660e..5d81462 100644
--- a/jinwei.me/infra/cloudflare.tf
+++ b/jinwei.me/infra/cloudflare.tf
@@ -50,3 +50,9 @@ resource "cloudflare_tunnel_config" "tunnel_route" {
50 } 50 }
51 } 51 }
52} 52}
53
54resource "aws_ssm_parameter" "cloudflare_tunnel_token" {
55 name = "/${local.name}/cloudflare/tunnel_token"
56 type = "SecureString"
57 value = cloudflare_argo_tunnel.tunnel.tunnel_token
58}
diff --git a/jinwei.me/infra/rds.tf b/jinwei.me/infra/rds.tf
index 381868e..3abac21 100644
--- a/jinwei.me/infra/rds.tf
+++ b/jinwei.me/infra/rds.tf
@@ -25,3 +25,33 @@ resource "random_password" "mysql_password" {
25 length = 16 25 length = 16
26 special = false 26 special = false
27} 27}
28
29resource "aws_ssm_parameter" "wordpress_db_host" {
30 name = "/${var.name}/mysql/host"
31 type = "String"
32 value = aws_db_instance.jinwei-me.address
33}
34
35resource "aws_ssm_parameter" "wordpress_db_port" {
36 name = "/${var.name}/mysql/port"
37 type = "String"
38 value = aws_db_instance.jinwei-me.port
39}
40
41resource "aws_ssm_parameter" "wordpress_db_name" {
42 name = "/${local.name}/mysql/name"
43 type = "String"
44 value = aws_db_instance.jinwei-me.db_name
45}
46
47resource "aws_ssm_parameter" "wordpress_db_user" {
48 name = "/${local.name}/mysql/username"
49 type = "String"
50 value = aws_db_instance.jinwei-me.username
51}
52
53resource "aws_ssm_parameter" "wordpress_db_password" {
54 name = "/${local.name}/mysql/password"
55 type = "SecureString"
56 value = random_password.mysql_password.result
57}
Powered by cgit v1.2.3 (git 2.41.0)