-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from kunalmemane/development
ci: CICD added for prod and dev environments
- Loading branch information
Showing
6 changed files
with
329 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
name: Test, Build and Deploy Area Calculator in Development | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- development # Trigger on push to the development branch | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.22' | ||
|
||
- name: Run tests | ||
run: make test | ||
|
||
- name: Build application | ||
run: make build | ||
|
||
# Setup S2i and Build container image | ||
- name: Install s2i | ||
run: | | ||
wget https://github.com/openshift/source-to-image/releases/download/v1.1.14/source-to-image-v1.1.14-874754de-linux-386.tar.gz | ||
tar -xvf source-to-image-v1.1.14-874754de-linux-386.tar.gz | ||
sudo mv s2i /usr/local/bin | ||
- name: s2i-build | ||
run: | | ||
sudo s2i build . quay.io/rh-ee-kmemane/go-s2i-builder quay.io/rh-ee-kmemane/area-calculator-development | ||
sudo docker images | ||
# Push Image to Quay registry | ||
- name: Push Application image to quay | ||
run: | | ||
sudo docker login quay.io -u "${{ secrets.QUAY_USERNAME }}" -p "${{ secrets.QUAY_PASSWORD }}" | ||
sudo docker push quay.io/rh-ee-kmemane/area-calculator-development | ||
# deploy application in ocp cluster | ||
- name: Authenticate and set context | ||
uses: redhat-actions/oc-login@v1 | ||
env: | ||
OPENSHIFT_USER: rh-ee-kmemane | ||
OPENSHIFT_NAMESPACE: rh-ee-kmemane-dev | ||
with: | ||
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }} | ||
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }} | ||
insecure_skip_tls_verify: true | ||
namespace: ${{ env.OPENSHIFT_NAMESPACE }} | ||
|
||
- name: Deploy application | ||
run: | | ||
if oc get svc -l app=area-calculator-dev --ignore-not-found; then | ||
oc delete svc,deployment,route,imagestream --selector app=area-calculator-dev; | ||
echo "deleted all resources with label app=area-calculator-dev"; | ||
fi | ||
oc new-app quay.io/rh-ee-kmemane/area-calculator-development --name=area-calculator-dev --labels=app=area-calculator-dev,env=dev | ||
oc expose svc area-calculator-dev --labels=env=dev | ||
oc get routes -l app=area-calculator-dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
name: Test, Build and Deploy Area Calculator in Production | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- main # Trigger on push to the main branch | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.22' | ||
|
||
- name: Run Test | ||
run: make test | ||
|
||
- name: Build application | ||
run: make build | ||
|
||
# s2i build and upload to quay | ||
- name: Install s2i | ||
run: | | ||
wget https://github.com/openshift/source-to-image/releases/download/v1.1.14/source-to-image-v1.1.14-874754de-linux-386.tar.gz | ||
tar -xvf source-to-image-v1.1.14-874754de-linux-386.tar.gz | ||
sudo mv s2i /usr/local/bin | ||
- name: s2i-build | ||
run: | | ||
sudo s2i build . quay.io/rh-ee-kmemane/go-s2i-builder quay.io/rh-ee-kmemane/area-calculator | ||
sudo docker images | ||
- name: Push Application image to quay | ||
run: | | ||
sudo docker login quay.io -u "${{ secrets.QUAY_USERNAME }}" -p "${{ secrets.QUAY_PASSWORD }}" | ||
sudo docker push quay.io/rh-ee-kmemane/area-calculator | ||
# deploy application in ocp cluster | ||
- name: Authenticate and set context | ||
uses: redhat-actions/oc-login@v1 | ||
env: | ||
OPENSHIFT_USER: rh-ee-kmemane | ||
OPENSHIFT_NAMESPACE: rh-ee-kmemane-dev | ||
with: | ||
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }} | ||
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }} | ||
insecure_skip_tls_verify: true | ||
namespace: ${{ env.OPENSHIFT_NAMESPACE }} | ||
|
||
- name: Deploy application | ||
run: | | ||
if oc get svc -l app=area-calculator-prod --ignore-not-found; then | ||
oc delete svc,deployment,route,imagestream --selector app=area-calculator-prod; | ||
echo "deleted all resources with label app=area-calculator-prod"; | ||
fi | ||
oc new-app quay.io/rh-ee-kmemane/area-calculator --name=area-calculator-prod --labels=app=area-calculator-prod,env=prod | ||
oc expose svc area-calculator-prod --labels=env=prod | ||
oc get routes -l app=area-calculator-prod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Test and Build Area Calculator on PR against main | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
branches: | ||
- main # Trigger on pull request to the main branch | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.22' | ||
|
||
- name: Run Test | ||
run: make test | ||
|
||
- name: Build application | ||
run: make build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
name: Test, Build and Release Area Calculator | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
tags: | ||
- 'v*' | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.22' | ||
|
||
- name: Generate changelog.md | ||
run: | | ||
make changelog > changelog.md | ||
cat changelog.md | ||
- name: Test | ||
run: make test | ||
|
||
- name: Build | ||
run: make build | ||
|
||
- name: Set binary path | ||
run: | | ||
binary_path=$(pwd)/bin/main | ||
echo "BIN_PATH=${binary_path}" >> $GITHUB_ENV | ||
- name: Create release | ||
id: create_release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
tag: ${{ github.ref_name }} | ||
run: | | ||
gh release create area-${{ github.ref_name }}-x86_64 \ | ||
--repo="$GITHUB_REPOSITORY" \ | ||
--title="${GITHUB_REPOSITORY#*/} ${tag#v}" \ | ||
--notes-file changelog.md | ||
- name: Upload Artifact | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
tag: ${{ github.ref_name }} | ||
run: | | ||
gh release upload area-${{ github.ref_name }}-x86_64 ${{ env.BIN_PATH }} --clobber | ||
# # s2i build and upload to quay | ||
# - name: Install s2i | ||
# run: | | ||
# wget https://github.com/openshift/source-to-image/releases/download/v1.1.14/source-to-image-v1.1.14-874754de-linux-386.tar.gz | ||
# tar -xvf source-to-image-v1.1.14-874754de-linux-386.tar.gz | ||
# sudo mv s2i /usr/local/bin | ||
|
||
# - name: Verify s2i version | ||
# run: sudo s2i version | ||
|
||
# - name: s2i-build | ||
# run: | | ||
# sudo s2i build . quay.io/rh-ee-kmemane/go-s2i-builder quay.io/rh-ee-kmemane/area-calculator | ||
# sudo docker images | ||
|
||
# - name: Push Application image to quay | ||
# run: | | ||
# sudo docker login quay.io -u "${{ secrets.QUAY_USERNAME }}" -p "${{ secrets.QUAY_PASSWORD }}" | ||
# sudo docker push quay.io/rh-ee-kmemane/area-calculator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/bash | ||
|
||
TAGS=($(git tag --sort=-creatordate | head -n 2)) | ||
LATEST_TAG="${TAGS[0]}" | ||
PREVIOUS_TAG="${TAGS[1]}" | ||
|
||
if [ ${#TAGS[@]} -lt 2 ]; then | ||
echo "Not enough tags found to generate changelog." | ||
exit 1 | ||
fi | ||
|
||
CURRENT_DATE=$(date "+%Y-%m-%d") | ||
|
||
echo -e "\n# Changelog\n" | ||
echo -e "## Release Notes from $PREVIOUS_TAG to $LATEST_TAG\n" | ||
echo -e "### $CURRENT_DATE\n" | ||
|
||
declare -A tag_map=( | ||
["chore"]="Minor change" | ||
["docs"]="Document" | ||
["feat"]="Feature Added" | ||
["bug"]="Fixed" | ||
["ci"]="CI" | ||
["refactor"]="Changed" | ||
["test"]="Test" | ||
) | ||
|
||
# Collect and categorize commit messages | ||
for type in "${!tag_map[@]}"; do | ||
|
||
title="${tag_map[$type]}" | ||
|
||
if git log "$PREVIOUS_TAG..$LATEST_TAG" --pretty='%h - %s (%an)' | grep -q "$type"; then | ||
echo -e "\n### $title \n" | ||
|
||
git log "$PREVIOUS_TAG..$LATEST_TAG" --pretty='%h - %s (%an)' | awk -v type="$type" '$0 ~ "^.{10}(" type ": )" { sub(type ": ", ""); print }' | ||
fi | ||
done | ||
|
||
echo -e "\nChangelog generated for release $LATEST_TAG." |