Skip to content

Commit

Permalink
Build and push docker image to containers registry
Browse files Browse the repository at this point in the history
  • Loading branch information
dphulkar-msft committed Sep 30, 2024
1 parent 2ceb944 commit e16f7aa
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 1 deletion.
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/

# Install dependencies
RUN \
apt update && \
apt --fix-broken install

ENTRYPOINT ["azcopy"]
CMD ["--help"]



13 changes: 13 additions & 0 deletions docker/DockerfileARM
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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/

# Install dependencies
RUN \
apt update && \
apt --fix-broken install

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

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

# Install dependencies
RUN \
apt update && \
apt --fix-broken install

ENTRYPOINT ["azcopy"]
CMD ["--help"]
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
27 changes: 27 additions & 0 deletions docker/buildandruncontainer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Build azcopy binary
cd ..
echo "Building azcopy"
./docker/build.sh
ls -l azcopy

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

./buildcontainer.sh Dockerfile x86_64

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

if [ $? = 0 ]; then
echo " **** Build successful, running container now ******"
docker run -it --rm \
--cap-add=SYS_ADMIN \
--device=/dev/fuse \
--security-opt apparmor:unconfined \
-e AZURE_STORAGE_ACCOUNT \
-e AZURE_STORAGE_ACCESS_KEY \
$tag
else
echo "Failed to build docker image"
fi
26 changes: 26 additions & 0 deletions docker/buildcontainer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

# 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"
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
45 changes: 45 additions & 0 deletions docker/dockerinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

# 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

# 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
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

13 changes: 13 additions & 0 deletions docker/publishcontainer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@


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

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

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

sudo docker logout azcopy.azurecr.io

34 changes: 33 additions & 1 deletion 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: build_and_push_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 @@ -1668,7 +1673,7 @@ stages:
azcopy --version
azcopy --help
displayName: 'Check Version and Help'
- stage: ReleaseToContainer
dependsOn: TestArtifacts
condition: succeeded('TestArtifacts')
Expand Down Expand Up @@ -1787,6 +1792,33 @@ 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.build_and_push_docker_image, true) }}:
- stage: CreateAndReleaseDockerImage
dependsOn: TestArtifacts
condition: succeeded('TestArtifacts')
jobs:
- job: BuildAndPushDockerImage
strategy:
matrix:
Ubuntu_amd64:
agentName: "blobfuse-ubuntu22"
vmImage: 'Ubuntu-22.04'
container: 'test-cnt-ubn-22'
pool:
vmImage: $(vmImage)

steps:
- script: |
sudo apt-get install $(tags) $(fuselib) -y
chmod 777 *.sh
./dockerinstall.sh
./buildcontainer.sh Dockerfile x86_64
./publishcontainer.sh $(AZCOPY_DOCKER_REG_USER) $(AZCOPY_DOCKER_REG_PWD) 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
- ${{ if eq(parameters.post_release, true) }}:
- stage: ReleaseToGithub
dependsOn: TestArtifacts
Expand Down

0 comments on commit e16f7aa

Please sign in to comment.