|
1 | | -name: GCP Deploy |
| 1 | +name: Deploy to Cloud Run |
| 2 | + |
| 3 | +env: |
| 4 | + SERVICE_NAME: gcp-deployment |
2 | 5 |
|
3 | 6 | on: |
4 | 7 | push: |
5 | 8 | branches: |
6 | | - - main # Change to your default branch if it's not main |
7 | | - pull_request: |
8 | | - branches: |
9 | | - - main # Change to your default branch if it's not main |
| 9 | + - main |
10 | 10 |
|
11 | 11 | jobs: |
12 | | - build: |
| 12 | + dockerize-and-deploy: |
13 | 13 | runs-on: ubuntu-latest |
14 | 14 |
|
15 | 15 | steps: |
16 | | - - name: Checkout code |
17 | | - uses: actions/checkout@v2 |
18 | | - |
19 | | - - name: Set up Docker Buildx |
20 | | - uses: docker/setup-buildx-action@v1 |
21 | | - |
22 | | - - name: Cache Docker layers |
23 | | - uses: actions/cache@v2 |
24 | | - with: |
25 | | - path: /tmp/.buildx-cache |
26 | | - key: ${{ runner.os }}-buildx-${{ github.sha }} |
27 | | - restore-keys: | |
28 | | - ${{ runner.os }}-buildx- |
29 | | -
|
30 | | - - name: Log in to Google Container Registry |
31 | | - env: |
32 | | - GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} |
33 | | - GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }} |
34 | | - run: | |
35 | | - echo "${GCP_SA_KEY}" | base64 --decode > ${HOME}/gcp-key.json |
36 | | - gcloud auth activate-service-account --key-file=${HOME}/gcp-key.json |
37 | | - gcloud config set project $GCP_PROJECT_ID |
38 | | - gcloud auth configure-docker |
39 | | -
|
40 | | - - name: Build Docker image |
41 | | - run: | |
42 | | - docker build -t gcr.io/${{ secrets.GCP_PROJECT_ID }}/gcp-automation:latest . |
43 | | -
|
44 | | - - name: Push Docker image |
45 | | - run: | |
46 | | - docker push gcr.io/${{ secrets.GCP_PROJECT_ID }}/gcp-automation:latest |
47 | | -
|
48 | | - - name: Deploy to Cloud Run |
49 | | - env: |
50 | | - GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} |
51 | | - run: | |
52 | | - gcloud run deploy gcp-automation \ |
53 | | - --image gcr.io/${{ secrets.GCP_PROJECT_ID }}/gcp-automation:latest \ |
54 | | - --platform managed \ |
55 | | - --region us-central1 \ |
56 | | - --allow-unauthenticated |
| 16 | + - name: Checkout repository |
| 17 | + uses: actions/checkout@v2 |
| 18 | + |
| 19 | + - name: Set up Google Cloud SDK |
| 20 | + uses: google-github-actions/[email protected] |
| 21 | + with: |
| 22 | + service_account_key: ${{ secrets.GCP_SA_KEY }} |
| 23 | + project_id: ${{ secrets.GCP_PROJECT_ID }} |
| 24 | + |
| 25 | + - name: Configure Docker |
| 26 | + run: | |
| 27 | + gcloud auth configure-docker |
| 28 | +
|
| 29 | + - name: Build and Push Docker Image |
| 30 | + run: | |
| 31 | + docker build -t gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.DOCKER_IMAGE_NAME }}:latest . |
| 32 | + docker push gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.DOCKER_IMAGE_NAME }}:latest |
| 33 | +
|
| 34 | + - name: Deploy to Cloud Run |
| 35 | + run: | |
| 36 | + gcloud run deploy $SERVICE_NAME \ |
| 37 | + --image gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.DOCKER_IMAGE_NAME }}:latest \ |
| 38 | + --platform managed \ |
| 39 | + --region us-central1 \ |
| 40 | + --allow-unauthenticated |
0 commit comments