Skip to content

Commit

Permalink
Merge pull request #1 from DFE-Digital/feature/sathish
Browse files Browse the repository at this point in the history
Feature/sathish
  • Loading branch information
SathishMani219 authored Feb 5, 2024
2 parents bf33759 + bc82c9d commit 5445b41
Show file tree
Hide file tree
Showing 5 changed files with 155 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}}"
24 changes: 24 additions & 0 deletions src/App/Dockerfile
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"]
10 changes: 10 additions & 0 deletions src/App/DotNet.Docker.csproj
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>
2 changes: 2 additions & 0 deletions src/App/Program.cs
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!");

0 comments on commit 5445b41

Please sign in to comment.