Skip to content

Commit 4cd6f73

Browse files
authored
Merge pull request #123 from mayurmadnani/main
ND064 Course 1 upgrades and fixes https://udacity.atlassian.net/browse/CONUPDATE-4103
2 parents 8ae903d + 7260a4b commit 4cd6f73

File tree

8 files changed

+101
-18
lines changed

8 files changed

+101
-18
lines changed

exercises/Vagrantfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ ENV["TERM"]="linux"
55
Vagrant.require_version ">= 2.2.10"
66
Vagrant.configure("2") do |config|
77
config.vm.provision "shell",
8-
inline: "sudo su - && zypper update && zypper install -y apparmor-parser"
8+
inline: "sudo zypper update -y && sudo zypper install -y apparmor-parser"
99

1010
# Set the image for the vagrant box
11-
config.vm.box = "opensuse/Leap-15.2.x86_64"
12-
# Set the image version
13-
config.vm.box_version = "15.2.31.632"
11+
config.vm.box = "opensuse/Leap-15.6.x86_64"
12+
config.vm.box_version = "15.6.13.356"
13+
config.vm.boot_timeout = 900
1414

1515
# Forward the ports from the guest VM to the local host machine
1616
config.vm.network "forwarded_port", guest: 8080, host: 8080
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## file location and name: # .github/workflows/python-version.yml
2+
3+
## Named of the workflow.
4+
name: Python version
5+
## Set the trigger policy.
6+
## In this case, the workflow is execute on a `push` event,
7+
## or when a new commit is pushed to the repository
8+
on: [push]
9+
## List the steps to be executed by the workflow
10+
jobs:
11+
## Set the name of the job
12+
check-python-version:
13+
## Configure the operating system the workflow should run on.
14+
## In this case, the job on Ubuntu
15+
runs-on: ubuntu-latest
16+
## Define a sequence of steps to be executed
17+
steps:
18+
## Use the public `checkout` action in version v2
19+
## to checkout the existing code in the repository
20+
- uses: actions/checkout@v2
21+
## Use the public `setup-python` action in version v2
22+
## to install python on the Ubuntu based environment
23+
- uses: actions/setup-python@v2
24+
## Executes the `python --version` command
25+
- run: python --version
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
Flask==2.1.0
2-
werkzeug==2.0.0
1+
Flask==3.1.0

solutions/go-helloworld/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:alpine
1+
FROM golang:1.22.2-alpine
22

33
WORKDIR /go/src/app
44

solutions/go-helloworld/main.go

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,63 @@
11
package main
22

33
import (
4+
"encoding/json"
45
"fmt"
6+
"log"
57
"net/http"
68
)
79

8-
func helloWorld(w http.ResponseWriter, r *http.Request){
9-
fmt.Fprintf(w, "Go - Hello World")
10+
// HealthCheckResponse represents the /status JSON structure
11+
type HealthCheckResponse struct {
12+
Result string `json:"result"`
13+
}
14+
15+
// MetricsData holds metric details
16+
type MetricsData struct {
17+
UserCount int `json:"UserCount"`
18+
UserCountActive int `json:"UserCountActive"`
19+
}
20+
21+
// MetricsResponse represents the /metrics JSON structure
22+
type MetricsResponse struct {
23+
Status string `json:"status"`
24+
Code int `json:"code"`
25+
Data MetricsData `json:"data"`
26+
}
27+
28+
func helloHandler(w http.ResponseWriter, r *http.Request) {
29+
log.Println("Main request successful")
30+
fmt.Fprintln(w, "Go - Hello World")
31+
}
32+
33+
func statusHandler(w http.ResponseWriter, r *http.Request) {
34+
log.Println("Status request successful")
35+
response := HealthCheckResponse{Result: "OK - healthy"}
36+
w.Header().Set("Content-Type", "application/json")
37+
json.NewEncoder(w).Encode(response)
38+
}
39+
40+
func metricsHandler(w http.ResponseWriter, r *http.Request) {
41+
log.Println("Metrics request successful")
42+
response := MetricsResponse{
43+
Status: "success",
44+
Code: 0,
45+
Data: MetricsData{
46+
UserCount: 140,
47+
UserCountActive: 23,
48+
},
49+
}
50+
w.Header().Set("Content-Type", "application/json")
51+
json.NewEncoder(w).Encode(response)
1052
}
1153

1254
func main() {
13-
http.HandleFunc("/", helloWorld)
14-
http.ListenAndServe(":6111", nil)
55+
http.HandleFunc("/", helloHandler)
56+
http.HandleFunc("/status", statusHandler)
57+
http.HandleFunc("/metrics", metricsHandler)
58+
59+
log.Println("Starting server on port 6111...")
60+
if err := http.ListenAndServe(":6111", nil); err != nil {
61+
log.Fatalf("Could not start server: %s\n", err)
62+
}
1563
}

solutions/python-helloworld/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.8
1+
FROM python:3.12
22
LABEL maintainer="Katie Gamanji"
33

44
COPY . /app

solutions/python-helloworld/app.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,23 @@
44

55
app = Flask(__name__)
66

7+
# Set up logging to a file
8+
formatter = logging.Formatter('%(asctime)s %(levelname)s: %(message)s')
9+
10+
file_handler = logging.FileHandler('app.log')
11+
file_handler.setLevel(logging.DEBUG)
12+
file_handler.setFormatter(formatter)
13+
14+
app.logger.setLevel(logging.DEBUG)
15+
app.logger.addHandler(file_handler)
16+
17+
# Also capture Werkzeug logs (for request info)
18+
werkzeug_logger = logging.getLogger('werkzeug')
19+
werkzeug_logger.setLevel(logging.INFO)
20+
werkzeug_logger.addHandler(file_handler)
21+
722
@app.route('/status')
8-
def healthcheck():
23+
def status():
924
response = app.response_class(
1025
response=json.dumps({"result":"OK - healthy"}),
1126
status=200,
@@ -32,7 +47,4 @@ def hello():
3247
return "Hello World!"
3348

3449
if __name__ == "__main__":
35-
## stream logs to a file
36-
logging.basicConfig(filename='app.log',level=logging.DEBUG)
37-
3850
app.run(host='0.0.0.0')
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
Flask==2.1.0
2-
werkzeug==2.0.0
1+
Flask==3.1.0

0 commit comments

Comments
 (0)