refactor amikon job: auto redeploy every 6 hours (#40)
This commit is contained in:
		
							parent
							
								
									d849019a20
								
							
						
					
					
						commit
						d88b5726be
					
				
					 3 changed files with 91 additions and 46 deletions
				
			
		
							
								
								
									
										36
									
								
								jobs/nginx/ams-amikon-update.hcl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								jobs/nginx/ams-amikon-update.hcl
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,36 @@ | |||
| job "ams-amikon-update" { | ||||
|   datacenters = ["aperture"] | ||||
|   type        = "batch" | ||||
| 
 | ||||
|   periodic { | ||||
|     crons            = ["0 */6 * * * *"] | ||||
|     prohibit_overlap = true | ||||
|   } | ||||
| 
 | ||||
|   group "ams-amikon-update" { | ||||
| 
 | ||||
|     task "ams-amikon-update" { | ||||
|       driver = "raw_exec" | ||||
| 
 | ||||
|       config { | ||||
|         command = "/bin/bash" | ||||
|         args    = ["local/script.sh"] | ||||
|       } | ||||
| 
 | ||||
|       template { | ||||
|         data = <<EOH | ||||
| #!/bin/bash | ||||
| 
 | ||||
| # stop the ams-amikon job | ||||
| nomad job stop ams-amikon | ||||
| sleep 1 | ||||
| # revert the ams-amikon job to the previous version | ||||
| # this will trigger a new deployment, which will pull the latest image | ||||
| nomad job revert ams-amikon $(($(nomad job inspect ams-amikon | jq '.Job.Version')-1)) | ||||
| EOH | ||||
|         destination = "local/script.sh" | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| } | ||||
| 
 | ||||
							
								
								
									
										55
									
								
								jobs/nginx/ams-amikon.hcl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								jobs/nginx/ams-amikon.hcl
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,55 @@ | |||
| job "ams-amikon" { | ||||
|   datacenters = ["aperture"] | ||||
| 
 | ||||
|   meta { | ||||
|     run_uuid = "${uuidv4()}" | ||||
|   } | ||||
| 
 | ||||
|   type = "service" | ||||
| 
 | ||||
|   group "ams-amikon" { | ||||
|     count = 1 | ||||
| 
 | ||||
|     network { | ||||
|       port "http" { | ||||
|         to = 80 | ||||
|       } | ||||
|     } | ||||
| 
 | ||||
|     service { | ||||
|       port = "http" | ||||
| 
 | ||||
|       check { | ||||
|         type = "http" | ||||
|         path = "/" | ||||
|         interval = "10s" | ||||
|         timeout = "2s" | ||||
|       } | ||||
|       tags = [ | ||||
|         "traefik.enable=true", | ||||
|         "traefik.http.routers.ams-amikon.rule=Host(`amikon.me`,`www.amikon.me`)", | ||||
|         "traefik.http.routers.ams-amikon.entrypoints=web,websecure", | ||||
|         "traefik.http.routers.ams-amikon.tls.certresolver=lets-encrypt", | ||||
|         "traefik.http.routers.ams-amikon.middlewares=www-redirect", | ||||
|         "traefik.http.middlewares.www-redirect.redirectregex.regex=^https?://www.amikon.me/(.*)", | ||||
|         "traefik.http.middlewares.www-redirect.redirectregex.replacement=https://amikon.me/$${1}", | ||||
|         "traefik.http.middlewares.www-redirect.redirectregex.permanent=true", | ||||
|       ] | ||||
|     } | ||||
| 
 | ||||
|     task "amikon-nginx" { | ||||
|       driver = "docker" | ||||
| 
 | ||||
|       config { | ||||
|         image = "ghcr.io/dcuams/amikon-site-v2:latest" | ||||
|         force_pull = true | ||||
|         ports = ["http"] | ||||
|       } | ||||
| 
 | ||||
|       resources { | ||||
|         cpu    = 100 | ||||
|         memory = 50 | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | @ -1,46 +0,0 @@ | |||
| job "nginx-ams" { | ||||
|   datacenters = ["aperture"] | ||||
| 
 | ||||
|   type = "service" | ||||
| 
 | ||||
|   group "ams-web" { | ||||
|     count = 1 | ||||
| 
 | ||||
|     network { | ||||
|       port "http" { | ||||
|         to = 80 | ||||
|       } | ||||
|     } | ||||
| 
 | ||||
|     service { | ||||
|       port = "http" | ||||
| 
 | ||||
|       check { | ||||
|         type = "http" | ||||
|         path = "/" | ||||
|         interval = "10s" | ||||
|         timeout = "2s" | ||||
|       } | ||||
|       tags = [ | ||||
|         "traefik.enable=true", | ||||
|         "traefik.http.routers.nginx-ams.rule=Host(`amikon.me`,`www.amikon.me`)", | ||||
|         "traefik.http.routers.nginx-ams.entrypoints=web,websecure", | ||||
|         "traefik.http.routers.nginx-ams.tls.certresolver=lets-encrypt", | ||||
|       ] | ||||
|     } | ||||
| 
 | ||||
|     task "webserver" { | ||||
|       driver = "docker" | ||||
| 
 | ||||
|       config { | ||||
|         image = "ghcr.io/dcuams/amikon-site-v2:latest" | ||||
|         ports = ["http"] | ||||
|       } | ||||
| 
 | ||||
|       resources { | ||||
|         cpu    = 100 | ||||
|         memory = 500 | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| } | ||||
		Loading…
	
		Reference in a new issue