diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..ce85812 --- /dev/null +++ b/.github/workflows/build.yml @@ -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 diff --git a/README.md b/README.md index c21cebb..fca05bc 100644 --- a/README.md +++ b/README.md @@ -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`