forked from ubicloud/ubicloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor github action to build docker image and set it in cloud run
- Loading branch information
Showing
2 changed files
with
80 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
name: Run Database Migrations & Deploy | ||
|
||
on: | ||
push: | ||
branches: | ||
- lantern-main | ||
- lantern-staging | ||
jobs: | ||
migrate: | ||
name: Migrate Database & Deploy | ||
runs-on: ubicloud | ||
permissions: | ||
contents: "read" | ||
id-token: "write" | ||
steps: | ||
- name: Set up environment | ||
id: set_env | ||
run: | | ||
if [[ ${{ github.ref }} == 'refs/heads/lantern-main' ]]; then | ||
echo "branch=production" >> $GITHUB_OUTPUT | ||
else | ||
echo "branch=staging" >> $GITHUB_OUTPUT | ||
fi | ||
echo "image=${IMAGE}" >> $GITHUB_OUTPUT | ||
env: | ||
IMAGE: ${{ format('{0}-docker.pkg.dev/{1}/lanterndata/lantern-ubicloud', secrets.GCP_REGION, secrets.GCP_PROJECT_ID) }} | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
# Setup Gcloud | ||
- name: "GCP Auth" | ||
id: "auth" | ||
uses: "google-github-actions/auth@v2" | ||
with: | ||
token_format: access_token | ||
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }} | ||
service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }} | ||
- name: "Set up Cloud SDK" | ||
uses: "google-github-actions/setup-gcloud@v2" | ||
|
||
# Build and push image | ||
- name: Login to GCR Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ secrets.GCP_REGION }}-docker.pkg.dev | ||
username: oauth2accesstoken | ||
password: ${{ steps.auth.outputs.access_token }} | ||
- name: Build and push | ||
uses: docker/build-push-action@v5 | ||
id: build_image | ||
with: | ||
context: . | ||
platforms: | | ||
linux/amd64 | ||
file: Dockerfile | ||
push: true | ||
tags: | | ||
${{ format('{0}:{1}', steps.set_env.outputs.image, github.sha) }} | ||
${{ format('{0}:{1}', steps.set_env.outputs.image, steps.set_env.outputs.branch) }} | ||
${{ (steps.set_env.outputs.branch == 'production' && format('{0}:latest', steps.set_env.outputs.image)) || '' }} | ||
# Migrate & Deploy | ||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: .tool-versions | ||
bundler-cache: true | ||
- name: Install dependencies | ||
run: bundle install | ||
|
||
- name: Run Migrate & Deploy | ||
env: | ||
CLOVER_DATABASE_URL: ${{ ( steps.set_env.outputs.branch == 'production' && secrets.DATABASE_URL_PRODUCTION) || secrets.DATABASE_URL_STAGING }} | ||
IMAGE_URL: ${{ format('{0}:{1}', steps.set_env.outputs.image, github.sha) }} | ||
SERVICE: ${{ ( steps.set_env.outputs.branch == 'production' && secrets.GCP_SERVICE_NAME_PRODUCTION) || secrets.GCP_SERVICE_NAME_STAGING }} | ||
REGION: ${{ secrets.GCP_REGION }} | ||
run: | | ||
bundle exec rake prod_up && \ | ||
gcloud run deploy $SERVICE --image $IMAGE_URL --region $REGION |
This file was deleted.
Oops, something went wrong.