Skip to content

Instantly share code, notes, and snippets.

View r4rohan's full-sized avatar
☁️
In the Cloud

Rohan Singh r4rohan

☁️
In the Cloud
View GitHub Profile
@r4rohan
r4rohan / index.js
Created October 19, 2022 12:15
Nodejs code to send Google Cloud Build status message to Slack Channel.
const { IncomingWebhook } = require('@slack/webhook');
const url = '[ENTER_YOUR_SLACK_TOKEN]';
const webhook = new IncomingWebhook(url);
// subscribeSlack is the main function called by Cloud Functions.
module.exports.subscribeSlack = (pubSubEvent, context) => {
const build = eventToBuild(pubSubEvent.data);
const status = ['SUCCESS', 'FAILURE', 'INTERNAL_ERROR', 'TIMEOUT', 'CANCELLED'];
if (status.indexOf(build.status) === -1) {
@r4rohan
r4rohan / tf-apply.yaml
Last active February 20, 2024 11:01
Build Config in YAML file for Google Cloud Build.
## This is for dependent pipeline, due to names it would be appearing below plan file.
steps:
- id: 'Pre Trigger Status Message'
name: 'alpine/curl'
entrypoint: sh
args:
- -c
- |
curl -X POST -H 'Content-type: application/json' --data '{"channel":"${_CHANNEL_ID}","blocks":[{"type":"section","text":{"type":"mrkdwn","text":"Build Started for *$TRIGGER_NAME*"}}]}' "${_SLACK_WEBHOOK}"
# this file only contains function logic of GCE Machine Image for Windows VM.
# for full code visit: https://github.com/r4rohan/cloud-scripts/blob/main/scripts/windows/windows-machine-image.ps1
.
.
.
function Machine_Image
{
param
(
[string] $vmName,
@r4rohan
r4rohan / disk-snapshot-windows-script.ps1
Last active April 26, 2022 11:33
Powershell script to create GCE Disk Snapshot before patching GCE VMs via VM Manager
Set-StrictMode -Version Latest;
$ErrorActionPreference = "Stop";
<#
.SYNOPSIS
This function calls the gcloud binary
.PARAMETER Arguments
Array of arguments to be passed to gcloud
@r4rohan
r4rohan / packer.json
Last active September 25, 2021 11:06
{
"variables": {
"account_file": "{{ env `GOOGLE_APPLICATION_CREDENTIALS` }}"
},
"builders": [
{
"type": "googlecompute",
"project_id": "GCP_PROJECT_ID",
"source_image_family": "ubuntu-2004-lts",
[Unit]
Description=Hello World Spring Boot Demo Service
[Service]
User=ubuntu
#change this to your workspace
WorkingDirectory=/home/ubuntu/exec-script
#path to executable
services:
- docker:18.09.9-dind
cache:
paths:
- .m2/repository
before_script:
- source ci/script.sh
@r4rohan
r4rohan / terraform.yml
Last active June 23, 2021 11:16
GitHub Actions Workflow Code for Terraform Automation
name: terraform-automation
on:
push:
paths:
- 'examples/**'
concurrency:
group: ${{ github.action == 'terraform-automation' }}
cancel-in-progress: true
# enter Google Cloud Platform Project ID in environment section and update GitHub URL in git clone stage
pipeline {
agent {
kubernetes {
defaultContainer 'jnlp'
yaml """
apiVersion: v1
kind: Pod
metadata:
# Backend DEV
# Replace {enter-your-GCP-Project-ID} with Google Cloud Platform Project ID
name: omegatrade-backend-dev
on:
push:
branches: [ main ]
defaults: