Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to GCP #73

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions .github/workflows/ci-and-cd-for-review.yml

This file was deleted.

55 changes: 52 additions & 3 deletions .github/workflows/ci-and-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,57 @@ on:
push:
branches:
- main
pull_request:
branches:
- main

permissions:
contents: read
id-token: write
deployments: write

env:
PROJECT_ID: sepomex-365521
IMAGE_NAME: sepomex
GAR_LOCATION: us-central1
REPOSITORY: icalialabs-sepomex
SERVICE: sepomex
REGION: us-central1

jobs:
test-and-build:
name: Integration
uses: ./.github/workflows/test-and-build.yml
build-and-push-to-gcp:
name: Build and Push to GCP
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v0
with:
token_format: access_token
workload_identity_provider: projects/582875546495/locations/global/workloadIdentityPools/github-pool/providers/github-provider
service_account: github-actions@sepomex-365521.iam.gserviceaccount.com

- name: Set up Google Cloud SDK
uses: google-github-actions/setup-gcloud@v0.6.0

- name: Docker Auth
id: docker-auth
uses: docker/login-action@v1
with:
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}
registry: ${{ env.GAR_LOCATION }}-docker.pkg.dev

- name: Build and Push Container
run: |-
docker build -t ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:${{ github.sha }} ./
docker push ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:${{ github.sha }}

- name: Deploy to Cloud Run
id: deploy
run: |-
gcloud run deploy ${{ env.SERVICE }} --image ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:${{ github.sha }} -q --region ${{ env.REGION }} --port 3000 --allow-unauthenticated
100 changes: 0 additions & 100 deletions .github/workflows/test-and-build.yml

This file was deleted.

3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ RUN SECRET_KEY_BASE=10167c7f7654ed02b3557b05b88ece rails secret > /dev/null
# Set the installed app directory as the working directory:
WORKDIR /workspaces/sepomex

# Grant permission
RUN ["chmod", "+x", "/workspaces/sepomex/bin/entrypoint"]

# Set the entrypoint script:
ENTRYPOINT [ "/workspaces/sepomex/bin/entrypoint" ]

Expand Down
24 changes: 24 additions & 0 deletions bin/entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env ruby

# frozen_string_literal: true

def set_given_or_default_command
ARGV.concat %w[puma] if ARGV.empty?
end

def execute_given_or_default_command
exec(*ARGV)
end

def run_database_migrations
raise('Migrations failed') unless system('rails db:migrate')
end

def run_database_seeds
raise('Seeds failed') unless system('rails db:seed')
end

set_given_or_default_command
run_database_migrations
run_database_seeds
execute_given_or_default_command