Update README.md #106
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI/CD Pipeline | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: [ self-hosted ] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Build Docker Image | |
run: docker build -t myapp-command:latest -f MBS-COMMAND.API/Dockerfile . | |
deploy: | |
needs: build | |
runs-on: [self-hosted] | |
# if: github.event_name == 'pull_request' && github.event.pull_request.merged == true | |
env: | |
CONTAINER_NAME: myappCommandContainer | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Deploy to Server | |
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 -p 4000:8080 --name $CNAME myapp-command:latest | |
- name: Notify Deployment | |
run: echo "Deployment completed successfully!" |