-
Notifications
You must be signed in to change notification settings - Fork 33
/
aws-image-job.yaml
75 lines (72 loc) · 3.19 KB
/
aws-image-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
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: {}
#hostNetwork: true # needed for imds access
securityContext:
runAsUser: 0 # needed for container mode dnf access
initContainers:
- name: payload
image: registry.redhat.io/openshift-sandboxed-containers/osc-podvm-payload-rhel9:1.5.1
imagePullPolicy: Always
volumeMounts:
- name: shared-data
mountPath: /payload
command: ["/bin/sh"]
args: ["-c", "cp /podvm-binaries.tar.gz /payload/"]
containers:
- name: aws-image-creation
image: registry.access.redhat.com/ubi9/ubi:9.1
volumeMounts:
- name: shared-data
mountPath: /payload
env:
- name: PODVM_DISTRO
value: rhel
# - 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
- |
yum install -y yum-utils make git
yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
yum -y install packer
PATH="/usr/bin:${PATH}"
packer plugins install github.com/hashicorp/amazon
git clone https://github.com/confidential-containers/cloud-api-adaptor.git
cd cloud-api-adaptor && git checkout fcbfb26bb567bfa5aa6dc934d4a43ef9c3b3e3bf && cd -
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 30 -s --show-error 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
export IMAGE_NAME=${IMAGE_NAME:-peer-pod-ami}
LIBC=gnu make BINARIES= PAUSE_BUNDLE= image && \
echo "Set the AMI_ID ^ in your Secret/peer-pods-secret or ConfigMap/peer-pods-cm object"
restartPolicy: Never