Skip to content

changes to project 1 #12

changes to project 1

changes to project 1 #12

name: Build image and deploy Prefect flow - Project 2
env:
PROJECT_NAME: project_2
on:
pull_request:
types:
- opened
paths:
- "project_1/**"
push:
branches:
- main
paths:
- "project_1/**"
workflow_dispatch:
jobs:
deploy-staging:
name: Deploy to staging
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
env:
ENVIRONMENT: stg
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Get commit hash
id: get-commit-hash
run: echo "COMMIT_HASH=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
- name: Build and push
id: build-docker-image
env:
GITHUB_SHA: ${{ steps.get-commit-hash.outputs.COMMIT_HASH }}
uses: docker/build-push-action@v5
with:
context: ${{ env.PROJECT_NAME }}/
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/${{ env.PROJECT_NAME }}:${{ env.GITHUB_SHA }}-stg
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"
- name: Prefect Deploy
env:
PREFECT_API_KEY: ${{ secrets.PREFECT_API_KEY }}
IMAGE_NAME: ${{ secrets.DOCKER_USERNAME }}/${{ env.PROJECT_NAME }}:${{ steps.get-commit-hash.outputs.COMMIT_HASH }}-${{ env.ENVIRONMENT }}
run: |
cd $PROJECT_NAME
pip install -r requirements.txt
prefect cloud workspace set -w sales-engineering/sandbox-kevin-stg
prefect deploy --all --prefect-file prefect.yaml
deploy-production:
name: Deploy to production
runs-on: ubuntu-latest
if: github.event_name == 'push'
env:
ENVIRONMENT: prod
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Get commit hash
id: get-commit-hash
run: echo "COMMIT_HASH=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
- name: Build and push
id: build-docker-image
env:
GITHUB_SHA: ${{ steps.get-commit-hash.outputs.COMMIT_HASH }}
uses: docker/build-push-action@v5
with:
context: ${{ env.PROJECT_NAME }}/
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/${{ env.PROJECT_NAME }}:${{ env.GITHUB_SHA }}-${{ env.ENVIRONMENT }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"
- name: Prefect Deploy
env:
PREFECT_API_KEY: ${{ secrets.PREFECT_API_KEY }}
IMAGE_NAME: ${{ secrets.DOCKER_USERNAME }}/${{ env.PROJECT_NAME }}:${{ steps.get-commit-hash.outputs.COMMIT_HASH }}-${{ env.ENVIRONMENT }}
run: |
cd $PROJECT_NAME
pip install -r requirements.txt
prefect cloud workspace set -w sales-engineering/sandbox-kevin
prefect deploy --all --prefect-file prefect.yaml