Skip to content

Commit

Permalink
passing arguments from workflow file to dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
SubhedarV authored Sep 30, 2024
1 parent 33a5a80 commit 95e88ba
Showing 1 changed file with 108 additions and 45 deletions.
153 changes: 108 additions & 45 deletions .github/workflows/tarrr_file.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,55 +137,118 @@ jobs:
run: |
echo "Contents of Dockerfile directory:"
ls -al ${{ github.workspace }}/${{ env.XRT_VERSION_PATCH }}/Dockerfile
shell: bash

- name: Build Docker images
shell: bash

- name: Build Docker images
run: |
set -e # Exit on any error
package_files=("$GITHUB_WORKSPACE/${{ env.XRT_VERSION_PATCH }}/Dockerfile/"*-xrt.rpm "$GITHUB_WORKSPACE/${{ env.XRT_VERSION_PATCH }}/Dockerfile/"*-xrt.deb)
if [ ${#package_files[@]} -eq 0 ]; then
echo "No package files found."
exit 1
fi
for package_file in "${package_files[@]}"; do
echo "Building image for $package_file"
image_tag=$(basename "$package_file" | sed 's/\.[^.]*$//')
if [[ "$package_file" == *"18.04"* ]]; then
base_image="ubuntu:18.04"
install_commands='apt-get update && apt-get install -y wget && dpkg -i /tmp/${PACKAGE_FILE} || apt-get install -f -y && rm -f /tmp/${PACKAGE_FILE} && dpkg -l | grep xrt'
elif [[ "$package_file" == *"20.04"* ]]; then
base_image="ubuntu:20.04"
install_commands='apt-get update && apt-get install -y wget && dpkg -i /tmp/${PACKAGE_FILE} || apt-get install -f -y && rm -f /tmp/${PACKAGE_FILE} && dpkg -l | grep xrt'
elif [[ "$package_file" == *"22.04"* ]]; then
base_image="ubuntu:22.04"
install_commands='apt-get update && apt-get install -y wget && dpkg -i /tmp/${PACKAGE_FILE} || apt-get install -f -y && rm -f /tmp/${PACKAGE_FILE} && dpkg -l | grep xrt'
elif [[ "$package_file" == *"8.1.1911"* ]]; then
base_image="centos:8"
install_commands='sed -i "s|^mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-* && sed -i "s|^#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-* && yum install -y epel-release && yum install -y dnf-plugins-core wget && yum config-manager --set-enabled powertools && yum clean all && yum install -y /tmp/${PACKAGE_FILE} && rm -f /tmp/${PACKAGE_FILE}'
elif [[ "$package_file" == *"amzn2"* ]]; then
base_image="amazonlinux:2"
install_commands='yum update -y && yum install -y wget gnupg2 && amazon-linux-extras install epel -y && yum install -y tar && yum install -y /tmp/${PACKAGE_FILE} && rm -f /tmp/${PACKAGE_FILE}'
else
echo "No matching base image found for $package_file"
exit 1
fi
echo "Using base image: $base_image"
docker build --build-arg BASE_IMAGE="$base_image" --build-arg PACKAGE_FILE=$(basename "$package_file") --build-arg INSTALL_COMMANDS="$install_commands" -t "xrt_image:$image_tag" -f "$GITHUB_WORKSPACE/${{ env.XRT_VERSION_PATCH }}/Dockerfile/Dockerfile" "$GITHUB_WORKSPACE/${{ env.XRT_VERSION_PATCH }}/Dockerfile"
done
- name: Authenticate with Harbor
run: |
set -e # Exit on any error
package_files=("$GITHUB_WORKSPACE/${{ env.XRT_VERSION_PATCH }}/Dockerfile/"*-xrt.rpm "$GITHUB_WORKSPACE/${{ env.XRT_VERSION_PATCH }}/Dockerfile/"*-xrt.deb)
echo "${{ secrets.HARBOR_PASSWORD }}" | docker login registry.amd.com -u '${{ secrets.HARBOR_USERNAME }}' --password-stdin
shell: bash

- name: Push Docker images to AMD Harbor
run: |
for package_file in "${{ github.workspace }}/${{ env.XRT_VERSION_PATCH }}/Dockerfile/"*-xrt.rpm "${{ github.workspace }}/${{ env.XRT_VERSION_PATCH }}/Dockerfile/"*-xrt.deb; do
image_tag=$(basename "$package_file" | sed 's/\.[^.]*$//')
echo "Pushing image xrt_image:$image_tag"
docker tag "xrt_image:$image_tag" "registry.amd.com/buildops/xrt_image:$image_tag"
docker push "registry.amd.com/buildops/xrt_image:$image_tag"
done
shell: bash











# - name: Build Docker images
# run: |
# set -e # Exit on any error
# package_files=("$GITHUB_WORKSPACE/${{ env.XRT_VERSION_PATCH }}/Dockerfile/"*-xrt.rpm "$GITHUB_WORKSPACE/${{ env.XRT_VERSION_PATCH }}/Dockerfile/"*-xrt.deb)

if [ ${#package_files[@]} -eq 0 ]; then
echo "No package files found."
exit 1
fi
# if [ ${#package_files[@]} -eq 0 ]; then
# echo "No package files found."
# exit 1
# fi

for package_file in "${package_files[@]}"; do
echo "Building image for $package_file"
image_tag=$(basename "$package_file" | sed 's/\.[^.]*$//')
# for package_file in "${package_files[@]}"; do
# echo "Building image for $package_file"
# image_tag=$(basename "$package_file" | sed 's/\.[^.]*$//')

# Use [[ ... ]] for Bash pattern matching
if [[ "$package_file" == *"18.04"* ]]; then
base_image="ubuntu:18.04"
elif [[ "$package_file" == *"20.04"* ]]; then
base_image="ubuntu:20.04"
elif [[ "$package_file" == *"22.04"* ]]; then
base_image="ubuntu:22.04"
elif [[ "$package_file" == *"8.1.1911"* ]]; then
base_image="centos:8"
elif [[ "$package_file" == *"amzn2"* ]]; then
base_image="amazonlinux:2"
# elif [[ "$package_file" == *"7.8.2003"* ]]; then
# base_image="centos:8"
else
echo "No matching base image found for $package_file"
exit 1
fi
# # Use [[ ... ]] for Bash pattern matching
# if [[ "$package_file" == *"18.04"* ]]; then
# base_image="ubuntu:18.04"
# elif [[ "$package_file" == *"20.04"* ]]; then
# base_image="ubuntu:20.04"
# elif [[ "$package_file" == *"22.04"* ]]; then
# base_image="ubuntu:22.04"
# elif [[ "$package_file" == *"8.1.1911"* ]]; then
# base_image="centos:8"
# elif [[ "$package_file" == *"amzn2"* ]]; then
# base_image="amazonlinux:2"
# # elif [[ "$package_file" == *"7.8.2003"* ]]; then
# # base_image="centos:8"
# else
# echo "No matching base image found for $package_file"
# exit 1
# fi

echo "Using base image: $base_image"
docker build --build-arg BASE_IMAGE="$base_image" --build-arg PACKAGE_FILE=$(basename "$package_file") -t "xrt_image:$image_tag" -f "$GITHUB_WORKSPACE/${{ env.XRT_VERSION_PATCH }}/Dockerfile/Dockerfile" "$GITHUB_WORKSPACE/${{ env.XRT_VERSION_PATCH }}/Dockerfile"
done
# echo "Using base image: $base_image"
# docker build --build-arg BASE_IMAGE="$base_image" --build-arg PACKAGE_FILE=$(basename "$package_file") -t "xrt_image:$image_tag" -f "$GITHUB_WORKSPACE/${{ env.XRT_VERSION_PATCH }}/Dockerfile/Dockerfile" "$GITHUB_WORKSPACE/${{ env.XRT_VERSION_PATCH }}/Dockerfile"
# done

- name: Authenticate with Harbor
run: |
echo "${{ secrets.HARBOR_PASSWORD }}" | docker login registry.amd.com -u '${{ secrets.HARBOR_USERNAME }}' --password-stdin
shell: bash
# - name: Authenticate with Harbor
# run: |
# echo "${{ secrets.HARBOR_PASSWORD }}" | docker login registry.amd.com -u '${{ secrets.HARBOR_USERNAME }}' --password-stdin
# shell: bash

- name: Push Docker images to AMD Harbor
run: |
for package_file in "${{ github.workspace }}/${{ env.XRT_VERSION_PATCH }}/Dockerfile/"*-xrt.rpm "${{ github.workspace }}/${{ env.XRT_VERSION_PATCH }}/Dockerfile/"*-xrt.deb; do
image_tag=$(basename "$package_file" | sed 's/\.[^.]*$//')
echo "Pushing image xrt_image:$image_tag"
docker tag "xrt_image:$image_tag" "registry.amd.com/buildops/xrt_image:$image_tag"
docker push "registry.amd.com/buildops/xrt_image:$image_tag"
done
shell: bash
# - name: Push Docker images to AMD Harbor
# run: |
# for package_file in "${{ github.workspace }}/${{ env.XRT_VERSION_PATCH }}/Dockerfile/"*-xrt.rpm "${{ github.workspace }}/${{ env.XRT_VERSION_PATCH }}/Dockerfile/"*-xrt.deb; do
# image_tag=$(basename "$package_file" | sed 's/\.[^.]*$//')
# echo "Pushing image xrt_image:$image_tag"
# docker tag "xrt_image:$image_tag" "registry.amd.com/buildops/xrt_image:$image_tag"
# docker push "registry.amd.com/buildops/xrt_image:$image_tag"
# done
# shell: bash

0 comments on commit 95e88ba

Please sign in to comment.