You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2022/07/03 10:03:16 UTC
[airflow-ci-infra] 01/01: Add packer configuration to build ARM docker instance
This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch add-packer-for-arm-docker-instance
in repository https://gitbox.apache.org/repos/asf/airflow-ci-infra.git
commit ce63fb305d5a82023baee28de4bc2f3f4009db84
Author: Jarek Potiuk <ja...@potiuk.com>
AuthorDate: Sun Jul 3 12:02:19 2022 +0200
Add packer configuration to build ARM docker instance
---
arm-docker-ami/packer/files/docker-permissions.sh | 18 ++++
.../packer/files/install-dependencies.sh | 22 +++++
arm-docker-ami/packer/linux-ami.pkr.hcl | 96 ++++++++++++++++++++++
arm-docker-ami/packer/vars/variables.pkrvars.hcl | 22 +++++
4 files changed, 158 insertions(+)
diff --git a/arm-docker-ami/packer/files/docker-permissions.sh b/arm-docker-ami/packer/files/docker-permissions.sh
new file mode 100644
index 0000000..cf1fb13
--- /dev/null
+++ b/arm-docker-ami/packer/files/docker-permissions.sh
@@ -0,0 +1,18 @@
+#!/usr/bin/env bash
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+sudo usermod -a -G docker ec2-user
diff --git a/arm-docker-ami/packer/files/install-dependencies.sh b/arm-docker-ami/packer/files/install-dependencies.sh
new file mode 100644
index 0000000..3486545
--- /dev/null
+++ b/arm-docker-ami/packer/files/install-dependencies.sh
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+yum update
+yum install docker --assumeyes
diff --git a/arm-docker-ami/packer/linux-ami.pkr.hcl b/arm-docker-ami/packer/linux-ami.pkr.hcl
new file mode 100644
index 0000000..64c6ecb
--- /dev/null
+++ b/arm-docker-ami/packer/linux-ami.pkr.hcl
@@ -0,0 +1,96 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+variable "vpc_id" {
+ type = string
+}
+variable "ami_name" {
+ type = string
+}
+variable "aws_regions" {
+ type = list(string)
+}
+variable "packer_role_arn" {
+ type = string
+}
+variable "session_manager_instance_profile_name" {
+ type = string
+}
+
+source "amazon-ebs" "docker-runner" {
+ region = var.aws_regions[0]
+ ami_name = "${var.ami_name}-v2"
+ ami_regions = var.aws_regions
+ tag {
+ key = "Name"
+ value = "arm-docker-ami"
+ }
+ snapshot_tag {
+ key = "Name"
+ value = "arm-docker-ami-root"
+ }
+ encrypt_boot = false
+ instance_type = "m6g.large"
+ communicator = "ssh"
+ ssh_username = "ec2-user"
+ ssh_interface = "session_manager"
+ iam_instance_profile = var.session_manager_instance_profile_name
+ subnet_filter {
+ # Just pick a random subnet in the VPC -- we only have the three defaults so this is fine!
+ random = true
+ }
+ vpc_id = var.vpc_id
+ source_ami_filter {
+ filters = {
+ virtualization-type = "hvm"
+ architecture= "arm64",
+ name = "amzn2-ami-kernel-5.10-hvm-*"
+ root-device-type = "ebs"
+ }
+ owners = ["amazon"]
+ most_recent = true
+ }
+}
+
+build {
+ sources = [
+ "source.amazon-ebs.docker-runner"
+ ]
+
+ provisioner "shell" {
+ inline = [
+ "echo Connected via SSM at '${build.User}@${build.Host}:${build.Port}'"
+ ]
+ }
+
+ # Since we connect as a non-root user, we have to "stage" the files to a writable folder, which we then move
+ # in to place with the approriate permissions via install-files.sh provisioner step
+ provisioner "shell" {
+ inline = [
+ "mkdir -p /tmp/etc-systemd-system /tmp/usr-local-sbin /tmp/usr-local-bin /tmp/etc-sudoers.d /tmp/etc-iptables /tmp/etc-cron.d"
+ ]
+ }
+ provisioner "shell" {
+ scripts = [
+ "./files/install-dependencies.sh",
+ "./files/docker-permissions.sh",
+ ]
+ execute_command = "chmod +x '{{ .Path }}'; sudo sh -c '{{ .Vars }} {{ .Path }}'"
+ environment_vars = [
+ ]
+ }
+}
diff --git a/arm-docker-ami/packer/vars/variables.pkrvars.hcl b/arm-docker-ami/packer/vars/variables.pkrvars.hcl
new file mode 100644
index 0000000..f01a76e
--- /dev/null
+++ b/arm-docker-ami/packer/vars/variables.pkrvars.hcl
@@ -0,0 +1,22 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+vpc_id = "vpc-d73487bd"
+ami_name = "arm-docker-ami"
+aws_regions = ["eu-central-1", "us-east-2"]
+packer_role_arn = "arn:aws:iam::827901512104:role/packer-role"
+session_manager_instance_profile_name = "packer_ssm_instance_profile"