ds-ami-local.pkr.hcl 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. variable "aws_access_key" {
  18. type = string
  19. description = "AWS access key"
  20. }
  21. variable "aws_secret_key" {
  22. type = string
  23. description = "AWS secret key"
  24. }
  25. variable "aws_region" {
  26. type = string
  27. description = "AWS region"
  28. default = "cn-north-1"
  29. }
  30. variable "ds_tar" {
  31. type = string
  32. description = "DolphinScheduler tar file location"
  33. }
  34. variable "ds_ami_name" {
  35. type = string
  36. description = "Name of DolphinScheduler AMI"
  37. default = "dolphinscheduler-ami"
  38. }
  39. packer {
  40. required_plugins {
  41. amazon = {
  42. version = ">= 0.0.1"
  43. source = "github.com/hashicorp/amazon"
  44. }
  45. }
  46. }
  47. source "amazon-ebs" "linux" {
  48. access_key = var.aws_access_key
  49. secret_key = var.aws_secret_key
  50. region = var.aws_region
  51. ami_name = var.ds_ami_name
  52. instance_type = "t2.micro"
  53. source_ami_filter {
  54. filters = {
  55. name = "al2022-ami-*"
  56. root-device-type = "ebs"
  57. virtualization-type = "hvm"
  58. architecture = "x86_64"
  59. }
  60. most_recent = true
  61. owners = ["amazon"]
  62. }
  63. ssh_username = "ec2-user"
  64. }
  65. build {
  66. name = "dolphinscheduler-ami"
  67. sources = ["source.amazon-ebs.linux"]
  68. provisioner "file" {
  69. source = var.ds_tar
  70. destination = "~/dolphinscheduler.tar.gz"
  71. }
  72. provisioner "shell" {
  73. inline = [
  74. "sudo yum remove -y java",
  75. "sudo yum install -y java-1.8.0-amazon-corretto.x86_64",
  76. "echo 'export JAVA_HOME=/etc/alternatives/jre' | sudo tee /etc/profile.d/java_home.sh",
  77. "sudo mkdir -p /opt/dolphinscheduler",
  78. "sudo tar zxvf /home/ec2-user/dolphinscheduler.tar.gz --strip-components 1 -C /opt/dolphinscheduler",
  79. "sudo find /opt/dolphinscheduler/ -name start.sh | xargs -I{} sudo chmod +x {}",
  80. ]
  81. }
  82. }