Skip to content

Merge pull request #74 from Eclipse-Dominator/link_execution_w_submis… #28

Merge pull request #74 from Eclipse-Dominator/link_execution_w_submis…

Merge pull request #74 from Eclipse-Dominator/link_execution_w_submis… #28

name: Selectively Build and Push to Artifact Registry
on:
push:
branches: ["master"]
env:
PROJECT_ID: cs3219-400714
REGION: asia-southeast1
GAR_LOCATION: asia-southeast1-docker.pkg.dev/cs3219-400714/peerprep/
jobs:
build-push-artifact:
runs-on: ubuntu-latest
outputs:
should_deploy: ${{ steps.deploy.outputs.BUILD_STEP_RAN }}
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
- name: Detect Changes in Microservices
id: changes
uses: dorny/paths-filter@v2
with:
filters: |
frontend:
- 'frontend/**'
user_service:
- 'user_service/**'
question_service:
- 'question_service/**'
matching_service:
- 'matching_service/**'
collab_service:
- 'collab_service/**'
code_execution:
- 'code_execution/**'
api_gateway:
- 'api_gateway/**'
- name: 'Create env file'
run: |
echo "${{ secrets.ENV_FILE }}" > .env
- name: "Set up google auth"
id: auth
uses: "google-github-actions/auth@v1"
with:
credentials_json: "${{ secrets.SERVICE_ACCOUNT_KEY }}"
- name: "Set up Cloud SDK"
uses: "google-github-actions/setup-gcloud@v1"
- name: "Use gcloud CLI"
run: "gcloud info"
- name: "Docker auth"
run: |-
gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev --quiet
- name: 1. Build and Push frontend
id: a
if: steps.changes.outputs.frontend == 'true'
run: |
docker-compose build frontend
docker-compose push frontend
- name: 2. Build and Push question-service
id: b
if: steps.changes.outputs.question_service == 'true'
run: |
docker-compose build question-service
docker-compose push question-service
- name: 3. Build and Push user-service
id: c
if: steps.changes.outputs.user_service == 'true'
run: |
docker-compose build user-service
docker-compose push user-service
- name: 4. Build and Push matching-service
id: d
if: steps.changes.outputs.matching_service == 'true'
run: |
docker-compose build matching-service
docker-compose push matching-service
- name: 5. Build and Push collab-service
id: e
if: steps.changes.outputs.collab_service == 'true'
run: |
docker-compose build collab-service
docker-compose push collab-service
- name: 6. Build and Push code-execution
id: f
if: steps.changes.outputs.code_execution == 'true'
run: |
docker-compose build code-execution
docker-compose push code-execution
- name: 7. Build and Push api-gateway
id: g
if: steps.changes.outputs.api_gateway == 'true'
run: |
docker-compose build api-gateway
docker-compose push api-gateway
- name: determine deploy step
id: deploy
if: ${{ steps.a.conclusion == 'success' || steps.b.conclusion == 'success' || steps.c.conclusion == 'success' || steps.d.conclusion == 'success' || steps.e.conclusion == 'success' || steps.f.conclusion == 'success' }}
run: |
echo "BUILD_STEP_RAN=true" >> $GITHUB_OUTPUT
deploy:
needs: build-push-artifact
if: ${{needs.build-push-artifact.outputs.should_deploy== 'true'}}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: "Set up google auth"
id: auth
uses: "google-github-actions/auth@v1"
with:
credentials_json: "${{ secrets.SERVICE_ACCOUNT_KEY }}"
- name: "Use gcloud CLI"
run: "gcloud info"
- name: "SSH to VM"
id: 'compute-ssh'
uses: 'google-github-actions/ssh-compute@v0'
with:
instance_name: 'peerprep-prod'
zone: 'asia-southeast1-b'
ssh_private_key: '${{ secrets.SSH_KEY }}'
command: 'echo "${{ secrets.ENV_FILE }}" | sudo tee /usr/src/peerprep/.env > /dev/null && sudo chmod 777 /usr/src/peerprep/scripts/init.sh && sudo /usr/src/peerprep/scripts/init.sh'
- id: 'test'
run: |-
echo '${{ steps.compute-ssh.outputs.stdout }}'
echo '${{ steps.compute-ssh.outputs.stderr }}'