Skip to content

Commit

Permalink
ci: Main branch cicd added
Browse files Browse the repository at this point in the history
  • Loading branch information
kunalmemane committed Oct 25, 2024
1 parent 432e412 commit d288a40
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 118 deletions.
28 changes: 13 additions & 15 deletions .github/workflows/development-cicd.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Go Test
name: Test, Build and Deploy Area Calculator in Development

on:
workflow_dispatch:
Expand All @@ -17,16 +17,15 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22' # Specify the Go version you want to use
go-version: '1.22'

- name: Run tests
run: make test # Run all tests
run: make test

- name: Build application
run: make build

# Setup S2i and Build container image
# 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
Expand All @@ -35,22 +34,21 @@ jobs:
- name: s2i-build
run: |
sudo s2i build . quay.io/rh-ee-kmemane/go-s2i-builder quay.io/rh-ee-kmemane/area-calculator
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
sudo docker push quay.io/rh-ee-kmemane/area-calculator-development
# deploy application in resource hub
# 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 }}
Expand All @@ -59,12 +57,12 @@ jobs:

- name: Deploy application
run: |
if oc get svc -l app=area-calculator --ignore-not-found; then
oc delete svc,deployment,route,imagestream --selector app=area-calculator;
echo "deleted all resources with label app=area-calculator";
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 --name=area-calculator
oc expose svc area-calculator
oc get routes
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
84 changes: 0 additions & 84 deletions .github/workflows/go-cicd.yaml

This file was deleted.

68 changes: 68 additions & 0 deletions .github/workflows/main-merge-cicd.yaml
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
27 changes: 27 additions & 0 deletions .github/workflows/main-pr-ci.yaml
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
85 changes: 85 additions & 0 deletions .github/workflows/release.yaml
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
Loading

0 comments on commit d288a40

Please sign in to comment.