Skip to content

Commit

Permalink
Add deployment to GCloud
Browse files Browse the repository at this point in the history
  • Loading branch information
dam5s committed Feb 14, 2024
1 parent 1e486d9 commit 16e578d
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
46 changes: 46 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Build app

on: push

jobs:
build:
env:
PROJECT_ID: ${{ secrets.GCLOUD_PROJECT_ID }}
SERVICE_ACCOUNT_KEY: ${{ secrets.GCLOUD_SERVICE_ACCOUNT_KEY }}
REGION: us-central1
runs-on: ubuntu-latest
steps:
- name: 'Check out code'
uses: actions/checkout@v4

- name: 'Install .NET'
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

- name: 'Test and build container'
run: |
make restore
make check
make damo.io.server.container
- name: 'GCloud Auth'
uses: google-github-actions/auth@v2
with:
project_id: ${{ env.PROJECT_ID }}
credentials_json: ${{ env.SERVICE_ACCOUNT_KEY }}

- name: 'Set up GCloud SDK'
uses: google-github-actions/setup-gcloud@v2
with:
version: '>= 363.0.0'

- name: 'Upload image to GCloud'
run: |
gcloud auth configure-docker ${REGION}-docker.pkg.dev
docker tag damo.io.server ${REGION}-docker.pkg.dev/${PROJECT_ID}/docker-images/damo.io.server:latest
docker push ${REGION}-docker.pkg.dev/${PROJECT_ID}/docker-images/damo.io.server:latest
- name: 'Deploy to GCloud'
run: |
gcloud run deploy damo-io-server --region ${REGION} --image ${REGION}-docker.pkg.dev/${PROJECT_ID}/docker-images/damo.io.server:latest
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,41 @@ necessary variables for the whole build.
### Running the build

```
dotnet run -p Build
make check
make damo.io.server.container
make damo.io.blog.container
```

## GCloud

### Initial container image setup

* Create Artifact Registry in cloud console, named `docker-images`
* Push image to registry, using Powershell:
```
$env:REGION="us-central1"
$env:PROJECT_ID="example-project-id-1000"
$env:IMAGE_NAME="damo.io.server"
gcloud auth configure-docker "${env:REGION}-docker.pkg.dev"
docker tag ${env:IMAGE_NAME} "${env:REGION}-docker.pkg.dev/${env:PROJECT_ID}/docker-images/${env:IMAGE_NAME}:latest"
docker push "${env:REGION}-docker.pkg.dev/${env:PROJECT_ID}/docker-images/${env:IMAGE_NAME}:latest"
```
### Initial cloud run setup
* In Cloud console > Cloud Run > Create Service
* Select the image we just pushed to our Artifact Registry
* Min: 0, Max: 1
* Ingress: All
* Authentication: Allow Unauthenticated
* "Create"
### Setting up service account and automation
* Create service account `github-actions-account`
* Role `Artifact Registry Writer`
* Role `Cloud Run Developer`
* Role `Service Account User`
* Create and download key, set as GitHub secret as a single line string
* Setup workflow as seen in `.github/workflows/build.yml`

0 comments on commit 16e578d

Please sign in to comment.