Skip to content

Commit 7d6b9e8

Browse files
authored
Merge pull request #4 from mustafa854/workflows
feat(customized actions): customized deploy.yml file to track version
2 parents 5398a83 + 8a19a80 commit 7d6b9e8

File tree

3 files changed

+60
-7
lines changed

3 files changed

+60
-7
lines changed

.github/workflows/deploy.yml

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,64 @@ name: Deploy
22

33
on:
44
push:
5-
branches: ['main']
5+
branches:
6+
- 'main'
7+
- 'staging'
8+
- 'develop'
69

710
jobs:
811
deploy:
912
runs-on: ubuntu-latest
1013

1114
steps:
12-
- uses: actions/checkout@v4
13-
- run: docker build --build-arg ENV=development -t mustafaeligere/dockersample:latest .
14-
- run: echo "${{secrets.DOCKERHUB_PASSWORD}}" | docker login -u ${{secrets.DOCKERHUB_USERNAME}} --password-stdin
15-
- run: docker push mustafaeligere/dockersample:latest
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Docker Buildx
19+
uses: docker/setup-buildx-action@v2
20+
21+
- name: Get current version
22+
id: version
23+
run: |
24+
# Determine version based on the branch
25+
if [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then
26+
ENVIRONMENT=prod
27+
elif [[ "${GITHUB_REF}" == "refs/heads/staging" ]]; then
28+
ENVIRONMENT=stag
29+
elif [[ "${GITHUB_REF}" == "refs/heads/develop" ]]; then
30+
ENVIRONMENT=dev
31+
fi
32+
33+
# Get the latest tag version
34+
VERSION=$(cat VERSION) # assuming you store the version in a file
35+
NEW_VERSION=$((VERSION + 1))
36+
echo $NEW_VERSION > VERSION
37+
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
38+
echo "ENVIRONMENT=$ENVIRONMENT" >> $GITHUB_ENV
39+
echo "Tagging as $ENVIRONMENT v$NEW_VERSION"
40+
41+
- name: Build Docker image
42+
run: |
43+
docker build --build-arg ENV=${{ env.ENVIRONMENT }} -t mustafaeligere/dockersample:${{ env.ENVIRONMENT }}-v${{ env.NEW_VERSION }} -t mustafaeligere/dockersample:live-${{ env.ENVIRONMENT }} .
44+
45+
- name: Log in to DockerHub
46+
run: echo "${{ secrets.DOCKERHUB_PASSWORD }}" | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
47+
48+
- name: Push Docker image
49+
run: |
50+
docker push mustafaeligere/dockersample:${{ env.ENVIRONMENT }}-v${{ env.NEW_VERSION }}
51+
docker push mustafaeligere/dockersample:live-${{ env.ENVIRONMENT }}
52+
53+
- name: Update VERSION file in repo
54+
run: |
55+
git config --local user.name "github-actions"
56+
git config --local user.email "github-actions@github.com"
57+
git add VERSION
58+
git commit -m "Bump $ENVIRONMENT version to v${NEW_VERSION}"
59+
git push origin ${{ github.ref }}
60+
61+
- name: Deploy to Kubernetes/AWS
62+
run: |
63+
# Deploy to Kubernetes or AWS using kubectl or CLI
64+
kubectl set image deployment/my-app my-app=mustafaeligere/dockersample:live-${{ env.ENVIRONMENT }} --record
65+
# Similar command for AWS EKS or ECS if needed

.github/workflows/integration.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Integration
22

33
on:
44
push:
5-
branches: ['main']
5+
branches: ['main', 'staging', 'develop']
66
pull_request:
7-
branches: ['main']
7+
branches: ['main', 'staging', 'develop']
88

99
jobs:
1010
build:

VERSION

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
prod=1
2+
stag=1
3+
dev=1

0 commit comments

Comments
 (0)