diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c6b7f43..b695425 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,14 +2,64 @@ name: Deploy on: push: - branches: ['main'] + branches: + - 'main' + - 'staging' + - 'develop' jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - run: docker build --build-arg ENV=development -t mustafaeligere/dockersample:latest . - - run: echo "${{secrets.DOCKERHUB_PASSWORD}}" | docker login -u ${{secrets.DOCKERHUB_USERNAME}} --password-stdin - - run: docker push mustafaeligere/dockersample:latest + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Get current version + id: version + run: | + # Determine version based on the branch + if [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then + ENVIRONMENT=prod + elif [[ "${GITHUB_REF}" == "refs/heads/staging" ]]; then + ENVIRONMENT=stag + elif [[ "${GITHUB_REF}" == "refs/heads/develop" ]]; then + ENVIRONMENT=dev + fi + + # Get the latest tag version + VERSION=$(cat VERSION) # assuming you store the version in a file + NEW_VERSION=$((VERSION + 1)) + echo $NEW_VERSION > VERSION + echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV + echo "ENVIRONMENT=$ENVIRONMENT" >> $GITHUB_ENV + echo "Tagging as $ENVIRONMENT v$NEW_VERSION" + + - name: Build Docker image + run: | + docker build --build-arg ENV=${{ env.ENVIRONMENT }} -t mustafaeligere/dockersample:${{ env.ENVIRONMENT }}-v${{ env.NEW_VERSION }} -t mustafaeligere/dockersample:live-${{ env.ENVIRONMENT }} . + + - name: Log in to DockerHub + run: echo "${{ secrets.DOCKERHUB_PASSWORD }}" | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin + + - name: Push Docker image + run: | + docker push mustafaeligere/dockersample:${{ env.ENVIRONMENT }}-v${{ env.NEW_VERSION }} + docker push mustafaeligere/dockersample:live-${{ env.ENVIRONMENT }} + + - name: Update VERSION file in repo + run: | + git config --local user.name "github-actions" + git config --local user.email "github-actions@github.com" + git add VERSION + git commit -m "Bump $ENVIRONMENT version to v${NEW_VERSION}" + git push origin ${{ github.ref }} + + - name: Deploy to Kubernetes/AWS + run: | + # Deploy to Kubernetes or AWS using kubectl or CLI + kubectl set image deployment/my-app my-app=mustafaeligere/dockersample:live-${{ env.ENVIRONMENT }} --record + # Similar command for AWS EKS or ECS if needed diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 6a3063c..d7ba148 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -2,9 +2,9 @@ name: Integration on: push: - branches: ['main'] + branches: ['main', 'staging', 'develop'] pull_request: - branches: ['main'] + branches: ['main', 'staging', 'develop'] jobs: build: diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..848615a --- /dev/null +++ b/VERSION @@ -0,0 +1,3 @@ +prod=1 +stag=1 +dev=1 \ No newline at end of file