From 10e077f780d6e5e0023d373fb2b44b9b4c29c13e Mon Sep 17 00:00:00 2001 From: Kevin Cameron Grismore Date: Tue, 5 Mar 2024 15:59:15 -0600 Subject: [PATCH] condense to one workflow file --- .github/workflows/project-2-deploy-prod.yaml | 61 ---------- .github/workflows/project-2-deploy-stg.yaml | 61 ---------- .github/workflows/project-2-deploy.yaml | 112 +++++++++++++++++++ project_2/prefect.yaml | 6 +- 4 files changed, 115 insertions(+), 125 deletions(-) delete mode 100644 .github/workflows/project-2-deploy-prod.yaml delete mode 100644 .github/workflows/project-2-deploy-stg.yaml create mode 100644 .github/workflows/project-2-deploy.yaml diff --git a/.github/workflows/project-2-deploy-prod.yaml b/.github/workflows/project-2-deploy-prod.yaml deleted file mode 100644 index e43c940..0000000 --- a/.github/workflows/project-2-deploy-prod.yaml +++ /dev/null @@ -1,61 +0,0 @@ -name: Build image and deploy Prefect flow - production - -env: - PROJECT_NAME: project_2 - -on: - push: - branches: - - main - paths: - - "project_2/**" - workflow_dispatch: - -jobs: - deploy: - name: Deploy to production - runs-on: ubuntu-latest - - 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 }}-prod - 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 }} - PREFECT_API_URL: ${{ secrets.PREFECT_PROD_WORKSPACE_URL }} - IMAGE_NAME: ${{ steps.build-docker-image.outputs.metadata.image.name }} - run: | - pip install -r $PROJECT_NAME/requirements.txt - prefect deploy --all --prefect-file $PROJECT_NAME/prefect.yaml diff --git a/.github/workflows/project-2-deploy-stg.yaml b/.github/workflows/project-2-deploy-stg.yaml deleted file mode 100644 index 54beab8..0000000 --- a/.github/workflows/project-2-deploy-stg.yaml +++ /dev/null @@ -1,61 +0,0 @@ -name: Build image and deploy Prefect flow - staging - -env: - PROJECT_NAME: project_2 - -on: - push: - branches: - - stg - paths: - - "project_2/**" - workflow_dispatch: - -jobs: - deploy: - name: Deploy to staging - runs-on: ubuntu-latest - - 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 }} - PREFECT_API_URL: ${{ secrets.PREFECT_STG_WORKSPACE_URL }} - IMAGE_NAME: ${{ steps.build-docker-image.outputs.metadata.image.name }} - run: | - pip install -r $PROJECT_NAME/requirements.txt - prefect deploy --all --prefect-file $PROJECT_NAME/prefect.yaml diff --git a/.github/workflows/project-2-deploy.yaml b/.github/workflows/project-2-deploy.yaml new file mode 100644 index 0000000..339b575 --- /dev/null +++ b/.github/workflows/project-2-deploy.yaml @@ -0,0 +1,112 @@ +name: Build image and deploy Prefect flow - Project 2 + +env: + PROJECT_NAME: project_2 + +on: + push: + branches: + - stg + - main + paths: + - "project_2/**" + workflow_dispatch: + +jobs: + deploy-staging: + name: Deploy to staging + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/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: ${{ steps.build-docker-image.outputs.metadata.image.name }} + run: | + pip install -r $PROJECT_NAME/requirements.txt + prefect cloud workspace set -w sales-engineering/sandbox-kevin-stg + prefect deploy --all --prefect-file $PROJECT_NAME/prefect.yaml + + deploy-production: + name: Deploy to production + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' + + 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 }}-prod + 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: ${{ steps.build-docker-image.outputs.metadata.image.name }} + run: | + pip install -r $PROJECT_NAME/requirements.txt + prefect cloud workspace set -w sales-engineering/sandbox-kevin + prefect deploy --all --prefect-file $PROJECT_NAME/prefect.yaml \ No newline at end of file diff --git a/project_2/prefect.yaml b/project_2/prefect.yaml index fce00cc..2dc33ff 100644 --- a/project_2/prefect.yaml +++ b/project_2/prefect.yaml @@ -7,19 +7,19 @@ push: - prefect_aws.deployments.steps.push_to_s3: requires: prefect-aws bucket: cicd-example-workspaces - folder: project_2 + folder: "{{ $PROJECT_NAME }}" credentials: "{{ prefect.blocks.aws-credentials.ecs-worker-changes }}" pull: - prefect_aws.deployments.steps.pull_from_s3: requires: prefect-aws bucket: cicd-example-workspaces - folder: project_2 + folder: "{{ $PROJECT_NAME }}" credentials: "{{ prefect.blocks.aws-credentials.ecs-worker-changes }}" deployments: - name: my-project-2-deployment - entrypoint: project_2/flow.py:hello + entrypoint: "{{ $PROJECT_NAME }}/flow.py:hello" work_pool: name: k8s-demo work_queue_name: default