Skip to content

Instantly share code, notes, and snippets.

View michaeldimoudis's full-sized avatar

Michael Dimoudis michaeldimoudis

View GitHub Profile
@michaeldimoudis
michaeldimoudis / Dockerfile
Last active June 29, 2021 20:27
Hardened ASP.NET Core 3.1 app on Alpine Dockerfile
ARG VERSION=3.1-alpine
# Acknowledgements:
# This file was dervied with the help of a combination of https://github.com/ironPeakServices/iron-alpine/blob/master/Dockerfile
# and these 2 blog posts https://medium.com/01001101/containerize-your-net-core-app-the-right-way-35c267224a8d and https://medium.com/asos-techblog/minimising-your-attack-surface-by-building-highly-specialised-docker-images-example-for-net-b7bb177ab647
# Stage 1: Build application
FROM mcr.microsoft.com/dotnet/core/sdk:$VERSION AS build-env
WORKDIR /build
@michaeldimoudis
michaeldimoudis / post-install.sh
Last active May 15, 2021 15:24
Post install script for Alpine docker images
#!/usr/bin/env sh
# Acknowledgement:
# Most of this file was derived from https://github.com/ironPeakServices/iron-alpine/blob/master/post-install.sh
# fail if a command fails
set -e
set -o pipefail
# remove apk package manager
@michaeldimoudis
michaeldimoudis / harden.sh
Last active November 21, 2022 17:19
Hardening script for Alpine docker images
#!/usr/bin/env sh
# Acknowledgements:
# Most of this file was derived from https://github.com/ironPeakServices/iron-alpine/blob/master/Dockerfile
# with some additions from https://medium.com/asos-techblog/minimising-your-attack-surface-by-building-highly-specialised-docker-images-example-for-net-b7bb177ab647
# fail if a command fails
set -e
set -o pipefail
@michaeldimoudis
michaeldimoudis / Dockerfile
Last active November 9, 2023 17:19
Hardened ASP.NET Core 3.1 Runtime Dockerfile
ARG VERSION=3.1-alpine
# Acknowledgements:
# This file was dervied with the help of a combination of https://github.com/ironPeakServices/iron-alpine/blob/master/Dockerfile
# and these 2 blog posts https://medium.com/01001101/containerize-your-net-core-app-the-right-way-35c267224a8d and https://medium.com/asos-techblog/minimising-your-attack-surface-by-building-highly-specialised-docker-images-example-for-net-b7bb177ab647
# Stage 1: Build application
FROM mcr.microsoft.com/dotnet/core/sdk:$VERSION AS build-env
WORKDIR /build
@michaeldimoudis
michaeldimoudis / LocalEntryPoint.cs
Created April 27, 2019 10:48
LocalEntryPoint.cs for custom resource serverless asp.net core web api
namespace AWSServerless1
{
/// <summary>
/// The Main function can be used to run the ASP.NET Core application locally using the Kestrel webserver.
/// It is now also the main entry point for the custom runtime.
/// </summary>
public class LocalEntryPoint
{
private static readonly LambdaEntryPoint LambdaEntryPoint = new LambdaEntryPoint();
private static readonly Func<APIGatewayProxyRequest, ILambdaContext, Task<APIGatewayProxyResponse>> Func = LambdaEntryPoint.FunctionHandlerAsync;
@michaeldimoudis
michaeldimoudis / AzureIoTHub.cs
Created January 12, 2019 03:32
Azure IoT Hub ConnectionStatusChanged(ConnectionStatus status, ConnectionStatusChangeReason reason)
private async Task ConnectionStatusChanged(ConnectionStatus status, ConnectionStatusChangeReason reason)
{
// https://github.com/Azure/azure-iot-sdk-csharp/pull/741
//Log.Information("Azure IoT Hub connection status Changed Status: {status} Reason: {reason}", status, reason);
//if (status == ConnectionStatus.Connected && reason == ConnectionStatusChangeReason.Connection_Ok)
//{
// Log.Information("Client connected (initially and after a successful retry).");
//}
@michaeldimoudis
michaeldimoudis / AzureIoTHub.cs
Created January 12, 2019 03:30
Azure IoT Hub Initialize()
public async Task Initialize()
{
while (true)
{
try
{
Log.Information("Azure IoT Hub trying to initialize");
_deviceClient = null;
_deviceClient = DeviceClient.CreateFromConnectionString(Config.DeviceConnectionString, TransportType.Mqtt);
_deviceClient.SetConnectionStatusChangesHandler(async (s, r) => await ConnectionStatusChanged(s, r));
@michaeldimoudis
michaeldimoudis / GPIO-WiringPi.md
Last active March 27, 2018 21:26
Pin reference for the Raspberry Pi B plus (B+) - Header P1
wPi Name Mode L R Mode Name wPi
3.3v 01 02 5v
8 SDA.1 ALT0 03 04 5V
9 SCL.1 ALT0 05 06 GND
7 GPIO. 7 IN 07 08 ALT0 TxD 15
GND 09 10 ALT0 RxD 16
0 GPIO. 0 IN 11 12 IN GPIO. 1 1
2 GPIO. 2 IN 13 14 GND
3 GPIO. 3 IN 15 16 IN GPIO. 4 4
@michaeldimoudis
michaeldimoudis / Appliance.service
Last active September 16, 2018 06:01
systems service definition file
[Unit]
Description=Appliance
Requires=network-online.target
After=network-online.target
[Service]
Type=simple
ExecStart=/home/pi/apps/Appliance/Appliance
Restart=always
StartLimitInterval=5min
@michaeldimoudis
michaeldimoudis / netcoreinstall.sh
Last active September 17, 2018 12:15
Install .NET Core 2.1 on Linux arm (Raspberry Pi - Raspbian)
# This will use the apt-get package manager to install three prerequiste packages.
sudo apt-get install curl libunwind8 gettext
# Download the latest .NET Core Runtime for ARM32. This is refereed to as armhf on the Daily Builds page https://github.com/dotnet/core-setup
wget -O dotnet.tar.gz https://dotnetcli.blob.core.windows.net/dotnet/Runtime/release/2.1/dotnet-runtime-latest-linux-arm.tar.gz
# Create a destination folder and extract the downloaded package into it.
sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet
# Set up a symbolic link to a directory on the path so we can call dotnet