-
Notifications
You must be signed in to change notification settings - Fork 33
/
aws-VM-image-create-job.yaml
109 lines (106 loc) · 4.59 KB
/
aws-VM-image-create-job.yaml
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
apiVersion: batch/v1
kind: Job
metadata:
name: aws-image-creation
namespace: openshift-sandboxed-containers-operator
spec:
parallelism: 1
completions: 1
backoffLimit: 1
template:
metadata:
name: aws-image-creation
spec:
volumes:
- name: shared-data
emptyDir: {}
volumes:
- name: image-id
emptyDir: {}
initContainers:
- name: payload
image: registry.redhat.io/openshift-sandboxed-containers/osc-podvm-payload-rhel9:latest
imagePullPolicy: Always
volumeMounts:
- name: shared-data
mountPath: /payload
command: ["/bin/sh"]
args: ["-c", "cp /podvm-binaries.tar.gz /payload/"]
restartPolicy: Never
containers:
- name: create
image: registry.access.redhat.com/ubi9/ubi:9.2
securityContext:
runAsUser: 0 # needed for container mode dnf access
volumeMounts:
- name: shared-data
mountPath: /payload
- name: image-id
mountPath: /output
env:
- name: CLOUD_PROVIDER
value: aws
- name: PODVM_DISTRO
value: rhel
- name: IMAGE_NAME
value: "peer-pod-ami"
# - name: INSTANCE_TYPE
# value: "t3.small" # default is t3.small, uncomment and modify if not available in your region
envFrom:
- secretRef:
name: peer-pods-secret
- configMapRef:
name: peer-pods-cm
optional: true
command:
- /bin/sh
- -c
- |
set -e
dnf install -y make git unzip
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
./aws/install
curl https://releases.hashicorp.com/packer/1.9.4/packer_1.9.4_linux_amd64.zip -o packer_1.9.4_linux_amd64.zip
echo "6cd5269c4245aa8c99e551d1b862460d63fe711c58bec618fade25f8492e80d9 packer_1.9.4_linux_amd64.zip" | sha256sum -c
unzip packer_1.9.4_linux_amd64.zip -d /usr/bin/
PATH="/usr/bin:${PATH}"
packer plugins install github.com/hashicorp/amazon
curl -L https://github.com/mikefarah/yq/releases/download/v4.35.2/yq_linux_amd64 -o /usr/bin/yq
echo "8afd786b3b8ba8053409c5e7d154403e2d4ed4cf3e93c237462dc9ef75f38c8d /usr/bin/yq" | sha256sum -c
chmod +x /usr/bin/yq
git clone https://github.com/confidential-containers/cloud-api-adaptor.git && (cd cloud-api-adaptor && git checkout 90ccfc3fa0ee56c2fc61b23ecf3731f819faf875)
[ "$BOOT_FIPS" == "true" ] && sed -i '/exit 0/ifips-mode-setup --enable' cloud-api-adaptor/aws/image/misc-settings.sh
tar xvf /payload/podvm-binaries.tar.gz -C cloud-api-adaptor/podvm/files
mkdir cloud-api-adaptor/podvm/files/pause_bundle # workaround to avoid pause image requirement
[[ ! "${VPC_ID}" ]] && [[ "${AWS_VPC_ID}" ]] && export VPC_ID=${AWS_VPC_ID}
[[ ! "${SUBNET_ID}" ]] && [[ "${AWS_SUBNET_ID}" ]] && export SUBNET_ID=${AWS_SUBNET_ID}
export MAC=$(curl -m 3 -s http://169.254.169.254/latest/meta-data/mac)
[[ ! "${AWS_REGION}" ]] && export AWS_REGION=$(curl -m 30 -s --show-error http://169.254.169.254/latest/meta-data/placement/region)
[[ ! "${AWS_REGION}" ]] && echo "AWS_REGION is missing" && exit 1
[[ ! "${VPC_ID}" ]] && export VPC_ID=$(curl -m 30 -s --show-error http://169.254.169.254/latest/meta-data/network/interfaces/macs/${MAC}/vpc-id)
[[ ! "${VPC_ID}" ]] && echo "VPC_ID is missing" && exit 1
[[ ! "${SUBNET_ID}" ]] && export SUBNET_ID=$(curl -m 30 -s --show-error http://169.254.169.254/latest/meta-data/network/interfaces/macs/${MAC}/subnet-id)
[[ ! "${SUBNET_ID}" ]] && echo "SUBNET_ID is missing" && exit 1
cd cloud-api-adaptor/aws/image
LIBC=gnu make BINARIES= PAUSE_BUNDLE= image && \
PODVM_AMI_ID=$(aws ec2 describe-images --query "Images[*].[ImageId]" --filters "Name=name,Values=${IMAGE_NAME}" --region ${AWS_REGION} --output text) && \
echo "PODVM_AMI_ID: \"$PODVM_AMI_ID\"" && \
echo ${PODVM_AMI_ID} > /output/image-id
- name: result
image: registry.access.redhat.com/ubi9/ubi:9.2
volumeMounts:
- name: image-id
mountPath: /output
envFrom:
- secretRef:
name: peer-pods-secret
- configMapRef:
name: peer-pods-cm
optional: true
command:
- /bin/sh
- -c
- |
while [ ! -f /output/image-id ]; do sleep 5; done
cat /output/image-id