-
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 #1 from DFE-Digital/feature/sathish
Feature/sathish
- Loading branch information
Showing
5 changed files
with
155 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}}" |
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,24 @@ | ||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS base | ||
WORKDIR / | ||
EXPOSE 8080 | ||
|
||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build | ||
WORKDIR / | ||
# Copy everything | ||
COPY src/ src/ | ||
# Restore as distinct layers | ||
#RUN dotnet restore | ||
# Build and publish a release | ||
RUN dotnet publish "src/App/DotNet.Docker.csproj" -c Release -o /out/publish | ||
RUN rm -rf /src | ||
|
||
|
||
# Build runtime image | ||
#FROM mcr.microsoft.com/dotnet/aspnet:8.0 | ||
FROM base AS final | ||
WORKDIR /src | ||
RUN useradd -m dotnet | ||
COPY --from=build /out/publish . | ||
RUN chown dotnet:dotnet /src . | ||
USER dotnet | ||
ENTRYPOINT ["dotnet", "DotNet.Docker.dll"] |
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,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
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,2 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
Console.WriteLine("Hello World!"); |