Skip to content

interact via shell script #3

interact via shell script

interact via shell script #3

Workflow file for this run

name: Build and Push Docker Image
on:
push:
branches:
- main # Trigger on pushes to the main branch
- microservice
workflow_dispatch: # Allow manual triggers
jobs:
test:
runs-on: ubuntu-latest
env:
FOO: bar
steps:
# Step 1: Checkout the repository
- name: Checkout Code
uses: actions/[email protected]
# Step 2: Set up Python environment
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
# Step 3: Install dependencies
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest pytest-cov
# Step 4: Run tests with coverage
- name: Run Tests with Coverage
run: |
PYTHONPATH=$(pwd):$PYTHONPATH pytest --cov=app --cov-report=xml --cov-report=html tests/
# Step 5: Upload coverage report as an artifact
- name: Upload Coverage Report
uses: actions/[email protected]
with:
name: coverage-report
path: htmlcov/
build-and-push:
needs: test
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the code
- name: Checkout code
uses: actions/[email protected]
- id: 'auth'
uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ secrets.GCLOUD_SA_KEY }}'
# Step 2: Set up Google Cloud SDK
- name: Set up Google Cloud SDK
uses: google-github-actions/[email protected]
with:
project_id: ${{ secrets.GCLOUD_PROJECT }}
# Step 3: Authenticate Docker with Google Cloud Artifact Registry
- name: Authenticate Docker with GCloud
run: |
gcloud config set account '${{ secrets.GCLOUD_SA_ACCOUNT }}'
gcloud auth configure-docker ${DOCKER_REGISTRY}
# Step 4: Build the Docker image
- name: Build Docker image
run: |
docker build -t ${IMAGE_NAME}:${IMAGE_TAG} .
echo ${IMAGE_NAME}
# Step 5: Push the Docker image to Google Cloud Artifact Registry
- name: Push Docker image
run: |
gcloud auth configure-docker ${DOCKER_REGISTRY}
docker push ${IMAGE_NAME}:${IMAGE_TAG}
env:
DOCKER_REGISTRY: us-east4-docker.pkg.dev
GCLOUD_PROJECT: ${{ secrets.GCLOUD_PROJECT }}
IMAGE_NAME: us-east4-docker.pkg.dev/${{ secrets.GCLOUD_PROJECT }}/dev-advocacy/adventure
IMAGE_TAG: latest
deploy:
needs:
- test
- build-and-push
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/[email protected]
- id: 'auth'
uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ secrets.GCLOUD_SA_KEY }}'
# Step 2: Set up Google Cloud SDK
- name: Set up Google Cloud SDK
uses: google-github-actions/[email protected]
with:
project_id: ${{ secrets.GCLOUD_PROJECT }}
- name: Deploy to Cloud Run
env:
REGION: us-east4
DOCKER_REGISTRY: us-east4-docker.pkg.dev
IMAGE_NAME: us-east4-docker.pkg.dev/${{ secrets.GCLOUD_PROJECT }}/dev-advocacy/adventure
IMAGE_TAG: latest
GCP_PROJECT_ID: ${{ secrets.GCLOUD_PROJECT }}
run: |
gcloud run deploy adventure \
--project ${GCP_PROJECT_ID} \
--image ${IMAGE_NAME}:${IMAGE_TAG} \
--region ${REGION} \
--port 3000 \
--timeout 6m \
--update-env-vars FOO=bar