Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added src for hello-arc-windows #21

Merged
merged 3 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions hello-arc-windows/src/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM azurearcjumpstart.azurecr.io/node-windows-servercore:ltsc2019

ARG IMAGE_CREATE_DATE
ARG IMAGE_VERSION
ARG IMAGE_SOURCE_REVISION

# Metadata as defined in OCI image spec annotations - https://github.com/opencontainers/image-spec/blob/master/annotations.md
LABEL org.opencontainers.image.title="Hello Arc!" \
org.opencontainers.image.description="Provides a demo app to deploy to an Azure Arc-enabled Kubernetes cluster. It displays a message, the name of the pod and details of the node it is deployed to." \
org.opencontainers.image.created=$IMAGE_CREATE_DATE \
org.opencontainers.image.version=$IMAGE_VERSION \
org.opencontainers.image.authors="Jan Egil Ring" \
org.opencontainers.image.url="azurearcjumpstart.azurecr.io/hello-arc:windows" \
org.opencontainers.image.documentation="https://github.com/microsoft/azure-arc-jumpstart-apps/tree/main/hello-arc-windows" \
org.opencontainers.image.vendor="Microsoft" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.source="https://github.com/microsoft/azure-arc-jumpstart-apps.git" \
org.opencontainers.image.revision=$IMAGE_SOURCE_REVISION

# Create app directory
RUN mkdir -p c:\app
WORKDIR c:\\app

# Install app dependencies
COPY package.json c:\\app
RUN npm install

# Bundle app source
COPY . c:\\app

#USER node
CMD [ "C:\\nodejs\\npm.cmd", "start" ]
19 changes: 19 additions & 0 deletions hello-arc-windows/src/app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "hello-kubernetes",
"version": "1.8.0",
"description": "Hello Kubernetes!",
"author": "Paul Bouwer",
"license": "MIT",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"bytes": "^3.1.0",
"express": "^4.17.1",
"express-handlebars": "^3.1.0",
"handlebars": "^4.7.6",
"minimist": ">=1.2.5",
"morgan": "^1.9.1"
}
}
28 changes: 28 additions & 0 deletions hello-arc-windows/src/app/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var express = require('express');
var exphbs = require('express-handlebars');
var app = express();
var os = require("os");
var morgan = require('morgan');

app.engine('handlebars', exphbs({defaultLayout: 'main'}));
app.set('view engine', 'handlebars');
app.use(express.static('static'));
app.use(morgan('combined'));

// Configuration
var port = process.env.PORT || 8080;
var message = process.env.MESSAGE || "Hello Azure Arc GitOps Demo!";

app.get('/', function (req, res) {
res.render('home', {
message: message,
platform: os.type(),
release: os.release(),
hostName: os.hostname()
});
});

// Set up listener
app.listen(port, function () {
console.log("Listening on: http://%s:%s", os.hostname(), port);
});
49 changes: 49 additions & 0 deletions hello-arc-windows/src/app/static/css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
body {
margin:0;
padding:0;
background-color:white;
}

div.main {
text-align: center;
}

div.main img {
margin: 40px 0;
}

div.content {
color:#f2f2f2;
}
.content #message {
margin: 10px 0 50px 0;
padding: 30px 0;
font-family: 'Ubuntu', sans-serif;
font-weight: 300;
font-size: 44pt;
background-color: #1a6ad3;
/* border-top: 2px solid #909090;
border-bottom: 2px solid #909090; */
}

.content #info {
margin: 0 auto;
font-family: 'Ubuntu', sans-serif;
font-weight: 300;
font-size: 16pt;
color: black;
}

.content #info table {
margin: 10px auto;
}

.content #info table th {
text-align: right;
padding-right: 20px;
}

.content #info table td {
text-align: left;
}

Binary file added hello-arc-windows/src/app/static/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions hello-arc-windows/src/app/views/home.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div id="message">
{{ message }}
</div>
<div id="info">
<table>
<tr>
<th>pod:</th>
<td>{{ hostName }}</td>
</tr>
<tr>
<th>node:</th>
<td>{{ platform }} ({{ release }})</td>
</tr>
</table>

</div>
18 changes: 18 additions & 0 deletions hello-arc-windows/src/app/views/layouts/main.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<title>Hello Kubernetes!</title>
<link rel="stylesheet" type="text/css" href="/css/main.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Ubuntu:300" >
</head>
<body>

<div class="main">
<img src="/images/logo.png"/>
<div class="content">
{{{body}}}
</div>
</div>

</body>
</html>
48 changes: 48 additions & 0 deletions hello-arc-windows/src/node/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
FROM mcr.microsoft.com/windows/servercore:ltsc2019

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

# PATH isn't actually set in the Docker image, so we have to set it from within the container
RUN $newPath = ('C:\nodejs;{0}\Yarn\bin;{1}' -f $env:LOCALAPPDATA, $env:PATH); \
Write-Host ('Updating PATH: {0}' -f $newPath); \
[Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Machine)
# doing this first to share cache across versions more aggressively

ENV NODE_VERSION 18.14.0
ENV NODE_SHA256 2e8f00da72f6bd993e3b980ff844b948baf936e1e67e3694a7a3e5f6f7c9beb4

RUN $url = ('https://nodejs.org/dist/v{0}/node-v{0}-win-x64.zip' -f $env:NODE_VERSION); \
Write-Host ('Downloading {0} ...' -f $url); \
Invoke-WebRequest -Uri $url -OutFile 'node.zip'; \
\
Write-Host ('Verifying sha256 ({0}) ...' -f $env:NODE_SHA256); \
if ((Get-FileHash node.zip -Algorithm sha256).Hash -ne $env:NODE_SHA256) { throw 'SHA256 mismatch' }; \
\
Write-Host 'Expanding ...'; \
Expand-Archive node.zip -DestinationPath C:\; \
\
Write-Host 'Renaming ...'; \
Rename-Item -Path ('C:\node-v{0}-win-x64' -f $env:NODE_VERSION) -NewName 'C:\nodejs'; \
\
Write-Host 'Removing ...'; \
Remove-Item node.zip -Force; \
\
Write-Host 'Verifying ("node --version") ...'; \
node --version; \
Write-Host 'Verifying ("npm --version") ...'; \
npm --version; \
\
Write-Host 'Complete.'

ENV YARN_VERSION 1.22.17

# "It is recommended to install Yarn through the npm package manager" (https://classic.yarnpkg.com/en/docs/install)
RUN Write-Host 'Installing "yarn" ...'; \
npm install --global ('yarn@{0}' -f $env:YARN_VERSION); \
\
Write-Host 'Verifying ("yarn --version") ...'; \
yarn --version; \
\
Write-Host 'Complete.'

CMD [ "node" ]
33 changes: 33 additions & 0 deletions hello-arc-windows/src/test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
cd /workspaces
git clone https://github.com/microsoft/azure-arc-jumpstart-apps.git

cd /workspaces/azure-arc-jumpstart-apps/hello-arc-windows/src

# Build Windows Server container image with Node installed, needed as Node does not have an official Windows image per 2023-02-08: https://github.com/nodejs/docker-node/pull/362
docker build ./node -t azurearcjumpstart.azurecr.io/node-windows-servercore:ltsc2019

docker push azurearcjumpstart.azurecr.io/node-windows-servercore:ltsc2019

# Build node application
docker build ./app -t azurearcjumpstart.azurecr.io/hello-arc:windows

docker push azurearcjumpstart.azurecr.io/hello-arc:windows

# Test locally
docker run -d -p 8080:8080 azurearcjumpstart.azurecr.io/hello-arc:windows

# AKS
az login
az aks get-credentials --resource-group aks-demo-rg --name aks-demo

# Test Linux image on AKS Linux node
kubectl run hello-arc-linux --image liorkamrat/hello-arc --overrides='{"apiVersion": "v1", "spec": {"nodeSelector": { "kubernetes.io/os": "linux" }}}'

# Verify app is working
kubectl port-forward hello-arc-linux 8080:8080

# Test Windows image on AKS Windows node
kubectl run hello-arc-windows --image azurearcjumpstart.azurecr.io/hello-arc:windows --overrides='{"apiVersion": "v1", "spec": {"nodeSelector": { "kubernetes.io/os": "windows" }}}'

# Verify app is working
kubectl port-forward hello-arc-windows 8080:8080