DEV Community

Leonard Soetedjo
Leonard Soetedjo

Posted on

Building container image in AWS CodeBuild with buildah

While I was trying out AWS CodeBuild, I realised that the available build images are only Amazon Linux 2 & Ubuntu 18.04. Being used to CentOS, I initially tested out using Amazon Linux 2.

However, Amazon Linux 2 is based on RHEL7. I faced issues in building image using buildah in Amazon Linux 2. As such, I decided to take the challenge to use custom image based on centos:latest, which buildah can be easily installed and configured.

When using custom image, there are a couple of things that need to be done as these will not be available in the image:

  1. install aws cli
  2. install buildah

1. Installing AWS CLI v2

As per AWS CLI's guide, we'll download & install the latest version:

curl -o
unzip -q
Enter fullscreen mode Exit fullscreen mode

2. Installing buildah

Installing buildah is simpler in CentOS8:

dnf install -y buildah fuse-overlayfs
Enter fullscreen mode Exit fullscreen mode

However, the build process was giving an error:
failed to mount overlay for metacopy check with "nodev,metacopy=on" options: invalid argument. Googling around, I found this issue

Error: failed to mount overlay for metacopy check with "nodev,metacopy=on" options: invalid argument #8118

Is this a BUG REPORT or FEATURE REQUEST? (leave only one on its own line)

/kind bug


Additional information you deem important (e.g. issue happens only occasionally):

Output of podman version:

podman version 2.1.1

Output of podman info --debug:

Error: failed to mount overlay for metacopy check with "nodev,metacopy=on" options: invalid argument

Package info (e.g. output of rpm -q podman or apt list podman):

(paste your output here)

Have you tested with the latest version of Podman and have you checked the Podman Troubleshooting Guide?

this is last version on fedora repo

Additional environment details (AWS, VirtualBox, physical, etc.): vps at provider of vps

. What needs to be done is to remove the metacopy=on in /etc/containers/storage.conf. Subsequently, the build is successful :)

Below is a summary of my CodeBuild's buildspec.yml (configured for terraform):

version: 0.2

      - dnf -y update

      - echo "Install aws cli v2"
      - dnf -y install unzip
      - curl -o
      - unzip -q
      - ./aws/install
      - export PATH=/usr/local/bin:$PATH

      - echo "Install buildah"
      - dnf install -y podman buildah fuse-overlayfs
      - sed -i 's/^mountopt =.*/mountopt = "nodev"/g' /etc/containers/storage.conf
      - echo "Login to ECR"
      - aws ecr get-login-password --region ${AWS_DEFAULT_REGION} | buildah login --username AWS --password-stdin ${REPO_URI}
      - echo "Build started on `date`"
      - cd ${CODEBUILD_SRC_DIR}
      - cat /etc/os-release
      - sh ${IMAGE_NAME}
      - echo "Build completed on `date`"
      - TAG=`date +%Y%m%d_%H%M%S`
      - echo "Pushing image to repository ${IMAGE_NAME}"
      - buildah push ${IMAGE_NAME} ${REPO_URI}/${IMAGE_NAME}:${TAG}
Enter fullscreen mode Exit fullscreen mode

With the above, I'm able to build the container image using buildah and pushing it to my container repo.

Top comments (0)