Merge pull request #173 from Homebrew/dependabot/github_actions/ruby/… #485
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
name: Test and deploy to GKE | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
permissions: | |
contents: read | |
jobs: | |
checks: | |
runs-on: ubuntu-latest | |
env: | |
BUNDLE_WITH: development | |
steps: | |
- name: Checkout | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 | |
with: | |
persist-credentials: false | |
- name: Set up Ruby | |
uses: ruby/setup-ruby@a6b46b8a08edb18935835849f2a17072d5cc8c73 # v1.192.0 | |
with: | |
bundler-cache: true | |
- name: Run RuboCop | |
run: bundle exec rubocop | |
- name: Build Docker image | |
run: docker build --build-arg RUBY_VERSION=$(cat .ruby-version) . | |
deploy: | |
needs: checks | |
if: github.repository_owner == 'Homebrew' && github.event_name == 'push' | |
runs-on: ubuntu-latest | |
environment: production | |
concurrency: production | |
env: | |
IMAGE: us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/homebrew-docker/ci-orchestrator:${{ github.sha }} | |
permissions: | |
contents: read | |
id-token: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 | |
with: | |
persist-credentials: false | |
- name: Authenticate to Google Cloud | |
id: gcloud-auth | |
uses: google-github-actions/auth@62cf5bd3e4211a0a0b51f2c6d6a37129d828611d # v2 | |
with: | |
token_format: access_token | |
workload_identity_provider: projects/${{ secrets.GCP_PROJECT_NUM }}/locations/global/workloadIdentityPools/ci-orchestrator-deploy/providers/github-actions | |
service_account: ci-orchestrator-deploy@${{ secrets.GCP_PROJECT_ID }}.iam.gserviceaccount.com | |
- name: Configure Docker | |
run: |- | |
echo ${{ steps.gcloud-auth.outputs.access_token }} | docker login -u oauth2accesstoken --password-stdin https://us-central1-docker.pkg.dev | |
- name: Build Docker image | |
run: |- | |
docker build --tag "$IMAGE" --build-arg RUBY_VERSION=$(cat .ruby-version) . | |
- name: Publish Docker image | |
run: |- | |
docker push "$IMAGE" | |
- name: Get GKE credentials | |
uses: google-github-actions/get-gke-credentials@6051de21ad50fbb1767bc93c11357a49082ad116 # v2 | |
with: | |
cluster_name: ci-orchestrator | |
location: us-central1-c | |
- name: Deploy Kubernetes | |
working-directory: deployment | |
env: | |
CERTBOT_EMAIL: ${{ secrets.CERTBOT_EMAIL }} | |
DOMAIN: ${{ secrets.DOMAIN }} | |
PUBLIC_IP: ${{ secrets.PUBLIC_IP }} | |
ORKA_BASE_URL: ${{ secrets.ORKA_BASE_URL }} | |
GITHUB_CLIENT_ID: ${{ secrets.GITHUBCLIENT_ID }} | |
GITHUB_ORGANISATION: ${{ github.repository_owner }} | |
GITHUB_INSTALLATION_ID: ${{ secrets.GITHUBAPP_INSTALLATION_ID }} | |
run: |- | |
sed -f /dev/stdin deployment.yml.in > deployment.yml <<SED_SCRIPT | |
s|@IMAGE@|$IMAGE|g | |
s|@CERTBOT_EMAIL@|$CERTBOT_EMAIL|g | |
SED_SCRIPT | |
sed -f /dev/stdin config.yml.in > config.yml <<SED_SCRIPT | |
s|@DOMAIN@|$DOMAIN|g | |
s|@PUBLIC_IP@|$PUBLIC_IP|g | |
s|@ORKA_BASE_URL@|$ORKA_BASE_URL|g | |
s|@GITHUB_CLIENT_ID@|$GITHUB_CLIENT_ID|g | |
s|@GITHUB_ORGANISATION@|$GITHUB_ORGANISATION|g | |
s|@GITHUB_INSTALLATION_ID@|$GITHUB_INSTALLATION_ID|g | |
SED_SCRIPT | |
kubectl apply -f . | |
kubectl rollout status statefulset/ci-orchestrator |