-
Notifications
You must be signed in to change notification settings - Fork 0
53 lines (44 loc) · 1.65 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
name: Deploy to Google Cloud
on:
push:
branches:
- main # Trigger deployment on push to main branch
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Google Cloud SDK
uses: google-github-actions/[email protected]
with:
version: 'latest'
project_id: ${{ secrets.PROJECT_ID }}
service_account_key: ${{ secrets.GOOGLE_CREDENTIALS }}
- name: Ensure SSH key exists
run: |
mkdir -p /home/runner/.ssh
if [ ! -f /home/runner/.ssh/google_compute_engine ]; then
ssh-keygen -t rsa -f /home/runner/.ssh/google_compute_engine -C "${{ secrets.GITHUB_ACTOR }}" -N ""
fi
env:
CLOUDSDK_METRICS_ENVIRONMENT: github-actions-setup-gcloud
- name: Add SSH key for Google Cloud
run: |
gcloud compute os-login ssh-keys add --key-file=/home/runner/.ssh/google_compute_engine.pub --project ${{ secrets.PROJECT_ID }}
env:
CLOUDSDK_METRICS_ENVIRONMENT: github-actions-setup-gcloud
- name: Debug SSH Keys
run: gcloud compute os-login ssh-keys list --project ${{ secrets.PROJECT_ID }}
env:
CLOUDSDK_METRICS_ENVIRONMENT: github-actions-setup-gcloud
- name: Add SSH key to SSH agent
run: |
eval "$(ssh-agent -s)"
ssh-add /home/runner/.ssh/google_compute_engine
- name: Deploy to Google Compute Engine
run: |
gcloud compute ssh trouys16@${{ secrets.INSTANCE_NAME }} \
--project ${{ secrets.PROJECT_ID }} \
--zone ${{ secrets.ZONE }} \
--command "cd /home/trouys16/Jobby && ./deploy.sh"