-
Notifications
You must be signed in to change notification settings - Fork 0
88 lines (76 loc) · 3.21 KB
/
build-and-deploy-core.yml
File metadata and controls
88 lines (76 loc) · 3.21 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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
name: Build and deploy core
on:
push
env:
GITHUB_REGISTRY: ghcr.io
GITHUB_IMAGE_NAME: ${{ github.repository }}/core
GCP_REGISTRY: europe-west4-docker.pkg.dev
GCP_PROJECT_ID: nanoapi-registry
GCP_REPOSITORY: nanoapi-registry
GCP_IMAGE_NAME: stackcore/core
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Deno
uses: denoland/setup-deno@v2
with:
deno-version: v2.4.0
- name: Build Deno application
run: |
deno install --allow-scripts --reload
deno task build:core
# GitHub Container Registry login
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.GITHUB_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# GCP Authentication
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
# Configure Docker for GCP
- name: Configure Docker for GCP Artifact Registry
run: gcloud auth configure-docker ${{ env.GCP_REGISTRY }}
# Build and push to both registries
- name: Build and push Docker image
# only build on main branch
if: github.ref == 'refs/heads/main'
uses: docker/build-push-action@v5
with:
context: packages/core
file: packages/core/Dockerfile
push: true
tags: |
${{ env.GITHUB_REGISTRY }}/${{ env.GITHUB_IMAGE_NAME }}:${{ github.ref_name }}
${{ env.GITHUB_REGISTRY }}/${{ env.GITHUB_IMAGE_NAME }}:${{ github.sha }}
${{ env.GCP_REGISTRY }}/${{ env.GCP_PROJECT_ID }}/${{ env.GCP_REPOSITORY }}/${{ env.GCP_IMAGE_NAME }}:${{ github.ref_name }}
${{ env.GCP_REGISTRY }}/${{ env.GCP_PROJECT_ID }}/${{ env.GCP_REPOSITORY }}/${{ env.GCP_IMAGE_NAME }}:${{ github.sha }}
# Output the image URLs for easy reference
- name: Output image URLs
# only output on main branch
if: github.ref == 'refs/heads/main'
run: |
echo "Images pushed to:"
echo "GitHub: ${{ env.GITHUB_REGISTRY }}/${{ env.GITHUB_IMAGE_NAME }}:${{ github.ref_name }}"
echo "GitHub: ${{ env.GITHUB_REGISTRY }}/${{ env.GITHUB_IMAGE_NAME }}:${{ github.sha }}"
echo "GCP: ${{ env.GCP_REGISTRY }}/${{ env.GCP_PROJECT_ID }}/${{ env.GCP_REPOSITORY }}/${{ env.GCP_IMAGE_NAME }}:${{ github.ref_name }}"
echo "GCP: ${{ env.GCP_REGISTRY }}/${{ env.GCP_PROJECT_ID }}/${{ env.GCP_REPOSITORY }}/${{ env.GCP_IMAGE_NAME }}:${{ github.sha }}"
# Update Cloud Run service with the new image
- name: Deploy to Cloud Run
# only deploy on main branch
if: github.ref == 'refs/heads/main'
run: |
gcloud run deploy stackcore-core \
--image=${{ env.GCP_REGISTRY }}/${{ env.GCP_PROJECT_ID }}/${{ env.GCP_REPOSITORY }}/${{ env.GCP_IMAGE_NAME }}:${{ github.ref_name }} \
--region=europe-west4 \
--platform=managed \
--allow-unauthenticated