generated from iqbalpa/nestjs-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
75 lines (63 loc) · 2.19 KB
/
deploy.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
name: Deploy to Google Cloud VM with Docker
on:
push:
branches:
- feat/docker
paths-ignore:
- README.md
- .gitignore
pull_request_target:
branches:
- master
types:
- closed
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Docker Hub Authentication
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build Docker Image
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ vars.DOCKER_IMAGE_NAME }}:latest .
- name: Tag Docker Image
run: docker tag ${{ secrets.DOCKERHUB_USERNAME }}/${{ vars.DOCKER_IMAGE_NAME }}:latest ${{ secrets.DOCKERHUB_USERNAME }}/${{ vars.DOCKER_IMAGE_NAME }}:latest
- name: Push Docker Image to Docker Hub
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ vars.DOCKER_IMAGE_NAME }}:latest
deploy:
runs-on: ubuntu-latest
needs: publish
steps:
- name: Set up Cloud CLI
uses: google-github-actions/setup-gcloud@v0.3.0
with:
project_id: ${{ secrets.GCE_PROJECT_ID }}
service_account_key: ${{ secrets.GCP_CREDENTIALS }}
export_default_credentials: true
- name: Access gcloud CLI
run: |
gcloud auth configure-docker
- name: Checkout repository
uses: actions/checkout@v3
- name: Copy docker-compose.yml into GCP Instance
uses: appleboy/scp-action@master
with:
host: ${{ secrets.GCP_VM_IP }}
username: ${{ secrets.GCP_USER }}
key: ${{ secrets.GCP_SSH_PRIVATE_KEY }}
source: 'docker-compose.yml'
target: '/home/${{ secrets.GCP_USER }}/docker-compose.yml'
- name: SSH into GCP and Run Docker Container
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.GCP_VM_IP }}
username: ${{ secrets.GCP_USER }}
key: ${{ secrets.GCP_SSH_PRIVATE_KEY }}
script: |
echo "hello this is from gcp vm"