Skip to content

Commit

Permalink
Fix deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
hburn7 committed Feb 18, 2025
1 parent 0903c27 commit 139a769
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
run: docker push stagecodes/otr-processor:${{ steps.determine_env.outputs.environment }}

0 comments on commit 139a769

Please sign in to comment.