Skip to content

feat(customized actions): customized deploy.yml file to track version #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 55 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Integration

on:
push:
branches: ['main']
branches: ['main', 'staging', 'develop']
pull_request:
branches: ['main']
branches: ['main', 'staging', 'develop']

jobs:
build:
Expand Down
3 changes: 3 additions & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
prod=1
stag=1
dev=1
Loading