Skip to content

Commit

Permalink
Build and push docker image to containers registry (#2817)
Browse files Browse the repository at this point in the history
  • Loading branch information
dphulkar-msft authored Oct 11, 2024
1 parent 8c32b42 commit 3a1c8bb
Show file tree
Hide file tree
Showing 10 changed files with 291 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Create container based on Ubuntu-22.04 Jammy Jellyfish image
FROM mcr.microsoft.com/mirror/docker/library/ubuntu:22.04

# Copy azcopy binary to executable path
COPY ./azcopy /usr/local/bin/

# Make azcopy executable
RUN chmod +x /usr/local/bin/azcopy

# Install dependencies
RUN \
apt update && \
apt-get install -y ca-certificates

WORKDIR /azcopy
CMD [ "azcopy" ]
16 changes: 16 additions & 0 deletions docker/DockerfileArm64
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Create container based on Ubuntu-22.04 Jammy Jellyfish image
FROM --platform=linux/arm64 mcr.microsoft.com/mirror/docker/library/ubuntu:22.04

# Copy azcopy binary to executable path
COPY ./azcopy /usr/local/bin/

# Make azcopy executable
RUN chmod +x /usr/local/bin/azcopy

# Install dependencies
RUN \
apt update && \
apt-get install -y ca-certificates

WORKDIR /azcopy
CMD [ "azcopy" ]
15 changes: 15 additions & 0 deletions docker/DockerfileMariner
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Create container based on Ubuntu-22.04 Jammy Jellyfish image
FROM mcr.microsoft.com/cbl-mariner/base/core:2.0

# Install dependencies
RUN tdnf update -y
RUN tdnf install -y ca-certificates

# Copy azcopy binary to executable path
COPY ./azcopy /usr/local/bin/

# Make azcopy executable
RUN chmod +x /usr/local/bin/azcopy

WORKDIR /azcopy
CMD [ "azcopy" ]
21 changes: 21 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Steps to Pull an Image from Azure Container Registry:

# 1. Login to Azure

az login

# 2. Login to the Azure Container Registry

az acr login --name azcopycontainers

# 3. List the Images in Your ACR

az acr repository list --name azcopycontainers --output table

# 4. Pull the Image

docker pull azcopycontainers.azurecr.io/<imagename>:<tag>

# 5. Run the Image

docker run --rm -it -v /local/path/to/mount:/azcopy azcopycontainers.azurecr.io/<imagename>:<tag> azcopy copy <source> <destination>
5 changes: 5 additions & 0 deletions docker/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
echo "Using Go - $(go version)"
rm -rf azcopy
rm -rf azure-storage-azcopy
go build -o azcopy
29 changes: 29 additions & 0 deletions docker/buildandruncontainer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Build azcopy binary
./dockerinstall.sh
./buildcontainer.sh Dockerfile ubuntu-x86_64

# Fetch the version of azcopy and extract the version number
azcopy_version=$(../azcopy --version | awk '{print $3}')

# Construct the Docker image tag using the fetched version
docker_image_tag="azure-azcopy-ubuntu-x86_64.$azcopy_version"

# If build was successful then launch a container instance
status=`docker images | grep $docker_image_tag`

curr_dir=`pwd`
mkdir -p $curr_dir/azcopy
echo "Hello World" > $curr_dir/azcopy/hello.txt

if [ $? = 0 ]; then
echo " **** Build successful, running container now ******"

# Debug: Check the tag being used
echo "Using Docker image: $docker_image_tag"

docker run -it --rm \
-v $curr_dir/azcopy:/azcopy \
$docker_image_tag azcopy --help
else
echo "Failed to build docker image"
fi
28 changes: 28 additions & 0 deletions docker/buildcontainer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

# Build azcopy binary
cd ..
echo "Building azcopy"
./docker/build.sh
ls -l azcopy

ver=`./azcopy --version | cut -d " " -f 3`
tag="azure-azcopy-$2.$ver"

# Cleanup older container image from docker
sudo docker image rm $tag -f

# Build new container image using current code
echo "Build container for azcopy"
cd -
cp ../azcopy ./azcopy
sudo docker build -t $tag -f $1 .

# List all images to verify if new image is created
sudo docker images

# Image build is executed so we can clean up temp executable from here
rm -rf ./azcopy

# If build was successful then launch a container instance
status=`sudo docker images | grep $tag`
echo $status
47 changes: 47 additions & 0 deletions docker/dockerinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Cleanup old installation
sudo apt remove docker-desktop
rm -r $HOME/.docker/desktop
sudo rm /usr/local/bin/com.docker.cli
sudo apt purge docker-desktop
sudo apt-get update

# Install certificates and pre-requisites
sudo apt-get install ca-certificates curl gnupg lsb-release -y
sudo mkdir -p /etc/apt/keyrings

# Create keyring for docker
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg -y

# Create file for installation
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"| sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Install docker
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y
sudo apt-get update

# Resolve permission issues to connect to docker socket
sudo groupadd docker
sudo usermod -aG docker $USER
sudo chown root:docker /var/run/docker.sock

# Create the .docker directory if it doesn't exist
mkdir -p $HOME/.docker
sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
sudo chmod g+rwx "$HOME/.docker" -R

# Delete old azcopy image
docker rmi `docker images | grep azcopy | cut -d " " -f1`

# Remove existing images
docker system prune -f

# Start docker service
sudo service docker start

# List docker container images
docker images ls

# List docker instances running
docker container ls

11 changes: 11 additions & 0 deletions docker/publishcontainer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ver=`../azcopy --version | cut -d " " -f 3`
image="azure-azcopy-$3.$ver"

sudo docker login azcopycontainers.azurecr.io --username $1 --password $2

# Publish Ubn-22 container image
sudo docker tag $image:latest azcopycontainers.azurecr.io/$image
sudo docker push azcopycontainers.azurecr.io/$image

sudo docker logout azcopycontainers.azurecr.io

103 changes: 103 additions & 0 deletions release-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ parameters:
type: boolean
default: false

- name: publish_docker_image
displayName: 'Build and Push Docker Image'
type: boolean
default: false

# Do not trigger this pipeline automatically
trigger: none
pr: none
Expand Down Expand Up @@ -1917,6 +1922,104 @@ stages:
AZCOPY_AUTO_LOGIN_TYPE=AzCLI $executable_name cp "$(Build.ArtifactStagingDirectory)/azCopy-binaries/azcopy_darwin_m1_arm64" "$m1_container_url" --put-md5=true
fi
- ${{ if eq(parameters.publish_docker_image, true) }}:
- stage: BuildAndPublishDockerImage
dependsOn: TestArtifacts
condition: succeeded('TestArtifacts')
jobs:
- job: Set_1_Ubuntu_Mariner_AMD64
strategy:
matrix:
Ubuntu_amd64:
agentName: "blobfuse-ubuntu22"
vmImage: 'Ubuntu-22.04'
container: 'test-cnt-ubn-22'
pool:
vmImage: $(vmImage)

variables:
- group: AZCOPY_SECRET_VAULT
- name: root_dir
value: '$(System.DefaultWorkingDirectory)'
- name: work_dir
value: '$(System.DefaultWorkingDirectory)/azure-storage-azcopy'

steps:
- checkout: none
- script: |
git clone https://github.com/Azure/azure-storage-azcopy
displayName: 'Checkout Code'
workingDirectory: $(root_dir)
- script: |
git checkout `echo $(Build.SourceBranch) | cut -d "/" -f 1,2 --complement`
displayName: 'Checkout branch'
workingDirectory: $(work_dir)
- script: |
chmod 777 *.sh
./dockerinstall.sh
./buildcontainer.sh Dockerfile ubuntu-x86_64
./publishcontainer.sh $(AZCOPY_DOCKER_REG_USER) $(AZCOPY_DOCKER_REG_PWD) ubuntu-x86_64
./buildcontainer.sh DockerfileMariner mariner-x86_64
./publishcontainer.sh $(AZCOPY_DOCKER_REG_USER) $(AZCOPY_DOCKER_REG_PWD) mariner-x86_64
displayName: "Create docker image and push to the containers registry"
workingDirectory: $(work_dir)/docker
- job: Set_2_Ubuntu_ARM64
timeoutInMinutes: 120
strategy:
matrix:
Ubuntu-22-ARM64:
vmImage: 'Ubuntu-22.04'
container: 'test-cnt-ubn-22-arm64'
AgentName: "blobfuse-ubn22-arm64"
pool:
name: "blobfuse-ubn-arm64-pool"
demands:
- ImageOverride -equals $(AgentName)

variables:
- group: AZCOPY_SECRET_VAULT
- name: root_dir
value: '$(System.DefaultWorkingDirectory)'
- name: work_dir
value: '$(System.DefaultWorkingDirectory)/azure-storage-azcopy'

steps:
- checkout: none
- script: |
git clone https://github.com/Azure/azure-storage-azcopy
displayName: 'Checkout Code'
workingDirectory: $(root_dir)
- script: |
git checkout `echo $(Build.SourceBranch) | cut -d "/" -f 1,2 --complement`
displayName: 'Checkout branch'
workingDirectory: $(work_dir)
- task: ShellScript@2
inputs:
scriptPath: "$(work_dir)/go_installer.sh"
args: "$(root_dir)/ $(AZCOPY_GOLANG_VERSION)"
displayName: "Installing Go tools"

- script: |
sudo apt update
sudo apt --fix-broken install
displayName: "Install dependencies"
- script: |
chmod 777 *.sh
./dockerinstall.sh
./buildcontainer.sh DockerfileArm64 ubuntu-arm64
./publishcontainer.sh $(AZCOPY_DOCKER_REG_USER) $(AZCOPY_DOCKER_REG_PWD) ubuntu-arm64
displayName: "Create docker image for arm64 and push to the containers registry"
workingDirectory: $(work_dir)/docker
- ${{ if eq(parameters.post_release, true) }}:
- stage: ReleaseToGithub
dependsOn: TestArtifacts
Expand Down

0 comments on commit 3a1c8bb

Please sign in to comment.