From 139a769343eba6a72f0f0681c72d6258c3c11862 Mon Sep 17 00:00:00 2001 From: hburn7 Date: Mon, 17 Feb 2025 20:13:06 -0500 Subject: [PATCH] Fix deploy script --- .github/workflows/deploy.yml | 41 ++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 46ed629..abfb1cf 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,31 +2,54 @@ name: Deploy to Staging and Production on: workflow_dispatch: + inputs: + branch: + description: 'Branch to deploy from' + required: true + default: 'master' + environment: + description: 'Environment to deploy to' + required: true + default: 'Staging' + type: choice + options: + - Staging + - Production push: branches: - master + tags: + - 'v*' jobs: deploy: runs-on: ubuntu-latest - strategy: - matrix: - environment: [Staging, Production] # Matrix strategy for environments env: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} - ENVIRONMENT: ${{ matrix.environment }} steps: - name: Checkout repository uses: actions/checkout@v4 - name: Log in to Docker Hub - run: echo "$DOCKERHUB_TOKEN" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin + run: echo "$DOCKERHUB_TOKEN" | docker login --username "$DOCKERHUB_USERNAME" --password-stdin + + - name: Determine environment + id: determine_env + run: | + if [[ ${{ github.event_name }} == 'workflow_dispatch' ]]; then + echo "Selected environment: ${{ github.event.inputs.environment }}" + echo "environment=${{ github.event.inputs.environment }}" >> $GITHUB_OUTPUT + elif [[ ${{ github.ref }} == 'refs/heads/master' ]]; then + echo "Deploying to Staging due to push to master" + echo "environment=Staging" >> $GITHUB_OUTPUT + elif [[ ${{ github.ref }} == refs/tags/v* ]]; then + echo "Deploying to Production due to tag creation" + echo "environment=Production" >> $GITHUB_OUTPUT + fi - name: Build Docker image - run: docker build -t stagecodes/otr-processor:${{ matrix.environment }} . + run: docker build -t stagecodes/otr-processor:${{ steps.determine_env.outputs.environment }} . - name: Push Docker image to Docker Hub - run: docker push stagecodes/otr-processor:${{ matrix.environment }} - - # No deployment job beyond upload, the server will run the latest image when necessary. \ No newline at end of file + run: docker push stagecodes/otr-processor:${{ steps.determine_env.outputs.environment }} \ No newline at end of file