-
Notifications
You must be signed in to change notification settings - Fork 0
49 lines (38 loc) · 1.27 KB
/
Copy pathcd-main.yml
File metadata and controls
49 lines (38 loc) · 1.27 KB
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
name: Build and Deploy Production
# Hanya trigger jika ada tag version
on:
push:
tags:
- 'v*.*.*'
jobs:
build-and-push:
name: Build & Push Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build Docker Image
run: |
echo "Building image with tag ${{ github.ref_name }}"
docker build -t pauwerfull/devops-node-api:${{ github.ref_name }} .
- name: Push Docker Image
run: |
docker push pauwerfull/devops-node-api:${{ github.ref_name }}
deploy-production:
name: Deploy to Production
needs: build-and-push
runs-on: self-hosted # runner VBOX
steps:
- name: Pull Docker Image
run: docker pull pauwerfull/devops-node-api:${{ github.ref_name }}
- name: Stop old container
run: docker stop node-api || true
- name: Remove old container
run: docker rm node-api || true
- name: Run new container
run: docker run -d -p 3000:3000 --name node-api pauwerfull/devops-node-api:${{ github.ref_name }}