-
Notifications
You must be signed in to change notification settings - Fork 1
50 lines (45 loc) · 1.6 KB
/
my-jobs.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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!"