Skip to content

Merge pull request #1 from bentran1vn/Entity #14

Merge pull request #1 from bentran1vn/Entity

Merge pull request #1 from bentran1vn/Entity #14

Workflow file for this run

name: My Jobs
on:
push:
branches:
- main
jobs:
build_and_deploy:
runs-on: [self-hosted]
env:
CONTAINER_NAME: myappCommandContainer
steps:
- uses: actions/checkout@v3
- name: Build Docker Image
run: docker build -t myapp-command:latest -f MBS-COMMAND.API/Dockerfile .
- name: Manage Docker Container and Build
run: |
CNAME=${{ env.CONTAINER_NAME }}
# Check if the container exists
if [ "$(docker ps -aq -f name=$CNAME)" ]; then
if [ "$(docker ps -aq -f status=exited -f name=$CNAME)" ]; then
echo ":: Container $CNAME exists and is exited"
echo ":: Removing exited container - $CNAME"
docker rm $CNAME
else
echo ":: Container $CNAME exists and is running"
echo ":: Stopping running container - $CNAME"
docker stop $CNAME
echo ":: Removing stopped container - $CNAME"
docker rm $CNAME
fi
else
echo ":: No existing container named $CNAME"
fi
# Run new container
echo ":: Running new container - $CNAME"
docker run -d --network=MBS --name $CNAME myapp-command:latest