Skip to content

Config/mail

Config/mail #31

Workflow file for this run

name: CI/CD Pipeline
on:
# push:
# branches:
# - '*' # Matches every branch
# - '!main' # Excludes main branch
pull_request:
types:
- closed
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!"