Skip to content

Commit

Permalink
split generation and execution of docker commands
Browse files Browse the repository at this point in the history
  • Loading branch information
heinpa committed Jun 28, 2024
1 parent 110a059 commit 2b8a4b1
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 54 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/deploy-component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,31 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Prepare deployment
run: bash -c ./service_config/prepare_deployment.sh
run: bash -c ./service_config/prepare_deployment.sh ./service_config/service_config.json
- name: "Deploy on DINO"
if: ${{ env.TARGET == 'DINO' }}
# ssh into server
run: bash -c ./service_config/generate_deployment_script.sh
uses: appleboy/scp-action@master
with:
host: ${{ secrets. SERVER_HOST }}
port : ${{ secrets.SERVER_PORT }}
username: ${{ secrets.SERVER_USERNAME }}
password: ${{ secrets.SERVER_PASSWORD }}
source: "./service_config/deploy_components.sh"
target: "/"
uses: appleboy/ssh-action@master
with:
host: ${{ secrets. SERVER_HOST }}
port : ${{ secrets.SERVER_PORT }}
username: ${{ secrets.SERVER_USERNAME }}
password: ${{ secrets.SERVER_PASSWORD }}
script: ./service_config/deploy_components.sh ./service_config/service_config.json
script: |
pwd
ls
chmod +x deploy_components.sh &&
./deploy_components.sh || true &&
rm deploy_component.sh
# use MSU to update on SWE
- name: "Deploy on SWE"
if: ${{ env.TARGET == 'SWE' }}
Expand Down
52 changes: 0 additions & 52 deletions service_config/deploy_components.sh

This file was deleted.

55 changes: 55 additions & 0 deletions service_config/generate_deployment_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

# deploy components manually using the existing configuration for MSU

env_files=$ENV_FILES

outfile="service_config/deploy_components.sh"
echo "" > $outfile

file=$1
if [ -z $file ]; then
echo "missing path to service config file (JSON)"
exit 0
fi
service_cnt=$(($(jq < $file | jq .services | jq length) - 1))

cnt=0
while [ $cnt -le $service_cnt ];
do
# collect data from service config
image=$(jq < $file | jq .services.[$cnt].image -r)
tag=$(jq < $file | jq .services.[$cnt].tag -r)
port_mapping=$(jq < $file | jq .services.[$cnt].port -r)
env_file=$(jq < $file | jq '.services.['$cnt'].files.".env"' -r)
container_name=${image/'/'/'-'}

volumes=$(jq < $file | jq .services.[$cnt].volumes -r)
if [ ! -z "${volumes}" ];then
volume_mappings=""
volume_cnt=$(($(echo $volumes | jq length) - 1))
i=0
while [ $i -le $volume_cnt ];
do
mapping=$(echo $volumes | jq .[$i] -r)
volume_mappings="$volume_mappings-v $mapping "
i=$(($i + 1))
done
fi

echo 'echo "Stopping and removing old container"' >> $outfile
echo 'docker stop $container_name || true && docker rm $container_name || true' >> $outfile
echo 'echo "Pulling image: $DOCKER_IMAGE_NAME' >> $outfile
echo 'docker pull "$image:$tag"' >> $outfile
echo 'echo "Starting container: $DOCKER_CONTAINER_NAME"' >> $outfile

if [ ! -z "${volume_mappings}" ];then
echo 'echo "docker run --restart=always -d -p $port_mapping $volume_mappings --env-file $env_files/$env_file --name $container_name $image:$tag" ' >> $outfile
echo '#docker run --restart=always -d -p $port_mapping $volume_mappings --env-file $env_files/$env_file --name $container_name "$image:$tag" ' >> $outfile
else
echo 'echo "docker run --restart=always -d -p $port_mapping --env-file $env_files/$env_file --name $container_name $image:$tag" ' >> $outfile
echo '#docker run --restart=always -d -p $port_mapping --env-file $env_files/$env_file --name $container_name "$image:$tag" ' >> $outfile
fi

cnt=$(($cnt + 1))
done

0 comments on commit 2b8a4b1

Please sign in to comment.