Skip to content

Commit

Permalink
push workflows and actions
Browse files Browse the repository at this point in the history
  • Loading branch information
SathishMani219 committed Feb 5, 2024
1 parent 7b1966e commit bc82c9d
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .github/actions/whats-my-ip-address/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Whats My Ip Address
description: Gets the workflow runner ip address

outputs:
ip:
description: The workflow runner's ip address
value: ${{ steps.whats-my-ip.outputs.ip }}

runs:
using: composite

steps:
- name: Get Workflow runner IP
shell: bash
id: whats-my-ip
run: |
# Resolving IP Address
# Function for unbuffered echo
function unbuffered_echo {
stdbuf -o 0 echo "$1"
}
# Maximum number of tries
max_tries=10
# Delay between tries in seconds
delay=0
#Curl Timeout
curl_timeout=30
for try in $(seq $max_tries); do
# Make a GET request to the API
response=$(curl --fail -m $curl_timeout -s https://api.ipify.org?format=json || true)
unbuffered_echo "Response: $response"
# Extract the IP address from the JSON response
ip=$(echo $response | jq -r '.ip')
# If the request was successful, print the IP and exit
if [[ $ip =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
unbuffered_echo "IP Address: $ip"
echo "ip=$ip" >> $GITHUB_OUTPUT
exit 0
fi
# If the request failed, wait and then try again
unbuffered_echo "Attempt $try failed, retrying in $delay seconds..."
sleep $delay
delay=$((delay + 2))
done
# If we reach this point, all attempts have failed
unbuffered_echo "Failed to retrieve IP after $max_tries attempts."
exit 1
61 changes: 61 additions & 0 deletions .github/workflows/buildimage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

name: Build Image and Publish to GCR

on:
workflow_dispatch :
# workflow_call:
inputs:
environment:
type: string
required: true

#on:
# push:
# branches: [ "main" ]

env:
DOCKER_IMAGE: Knowledgebase

jobs:

build-image:

runs-on: ubuntu-22.04
name: Build & Publish Image

steps:

- name: Checkout Repository
uses: actions/checkout@v3
with:
ref: ${{ github.ref }}

- name: Get GitHub Runner IP
id: whats-my-ip
uses: ./.github/actions/whats-my-ip-address


- name: GitHub Container Registry Login
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build Image & Publish To GCR
uses: docker/build-push-action@v4
with:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: docker.pkg.github.com
context: ./
file: ./src/App/Dockerfile
run: |
docker build . --tag ghcr.io/DFE-Digital/sts-knowledgebase/App:latest
docker push ghcr.io/DFE-Digital/sts-knowledgebase/App:latest
tags: |
ghcr.io/DFE-Digital/sts-knowledgebase/${{ env.DOCKER_IMAGE}}/${{github.run_number}}
push: true

- run :
echo "${{vars.AZ_ENVIRONMENT}}"

0 comments on commit bc82c9d

Please sign in to comment.