-
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.
- Loading branch information
1 parent
7b1966e
commit bc82c9d
Showing
2 changed files
with
119 additions
and
0 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,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 |
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,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}}" |