Linux ~ THE Sh script is a summary of its own, and the linuxsh script

Source: Internet
Author: User
Tags docker ps docker compose

Linux ~ THE Sh script is a summary of its own, and the linuxsh script

From. from the perspective of the netCore open-source project, eShopOnContainers is deployed across platforms. It can be deployed on linux, docker, and linux. It can also write integrated small scripts, this is an SH script for engineers to provide us with a deployment and release solution.

#!/bin/bashdeclare -a projectList=(    '../src/Services/Catalog/Catalog.API'    '../src/Services/Basket/Basket.API'    '../src/Services/Ordering/Ordering.API'    '../src/Services/Identity/Identity.API'    '../src/Web/WebMVC'    '../src/Web/WebSPA'    '../src/Web/WebStatus')# Build SPA app# pushd $(pwd)../src/Web/WebSPA# npm run build:prodfor project in "${projectList[@]}"do    echo -e "\e[33mWorking on $(pwd)/$project"    echo -e "\e[33m\tRemoving old publish output"    pushd $(pwd)/$project    rm -rf obj/Docker/publish    echo -e "\e[33m\tRestoring project"    dotnet restore    echo -e "\e[33m\tBuilding and publishing projects"    dotnet publish -o obj/Docker/publish    popddone# remove old docker images:images=$(docker images --filter=reference="eshop/*" -q)if [ -n "$images" ]; then    docker rm $(docker ps -a -q) -f    echo "Deleting eShop images in local Docker repo"    echo $images    docker rmi $(docker images --filter=reference="eshop/*" -q) -ffi# No need to build the images, docker build or docker compose will# do that using the images and containers defined in the docker-compose.yml file.

The above solution mainly reflected some commands used during the release, such as arrays, traversal, conditional statements, deletion of files, and release statements. I wrote and practiced it myself.

Declare-a arr = (12345) for I in "$ {arr [@]}" do if [$ I = 2] then echo "a is equal to 2" else echo "a is not equal to 2" fidonedeclare-a projectList = ('.. /src/Services/Catalog. API ''.. /src/Services/Basket. API ''.. /src/Services/Ordering. API ''.. /src/Services/Identity. API ''.. /src/Web/WebMVC ''.. /src/Web/WebSPA ''.. /src/Web/WebStatus ') for project in "$ {projectList [@]}" do echo-e "\ e [33m working in directory $ (pwd) /$ project "echo-e" \ e [33m \ tRemoving old publish output "done

When writing SH files, you should note that the carriage returns for linux and windows are different. We can download the notepad ++ tool for transcoding.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.