-
Notifications
You must be signed in to change notification settings - Fork 14
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 #3 from giannisalinetti/main
Add materials for chapters 9 and 10
- Loading branch information
Showing
18 changed files
with
298 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,19 @@ | ||
docker.io: | ||
tls-verify: true | ||
images: | ||
alpine: [] | ||
nginx: | ||
- "latest" | ||
images-by-tag-regex: | ||
httpd: ^2\.4\.[0-9]*-alpine$ | ||
quay.io: | ||
tls-verify: true | ||
images: | ||
fedora/fedora: | ||
- latest | ||
registry.access.redhat.com: | ||
tls-verify: true | ||
images: | ||
ubi8: | ||
- "8.4" | ||
- "8.5" |
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,9 @@ | ||
k8s.gcr.io: | ||
tls-verify: true | ||
images-by-tag-regex: | ||
kube-apiserver: ^v1\.22\..* | ||
kube-controller-manager: ^v1\.22\..* | ||
kube-proxy: ^v1\.22\..* | ||
kube-scheduler: ^v1\.22\..* | ||
coredns/coredns: ^v1\.8\..* | ||
etcd: 3\.4.[0-9]*-[0-9]* |
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,27 @@ | ||
version: 0.1 | ||
log: | ||
fields: | ||
service: registry | ||
storage: | ||
cache: | ||
blobdescriptor: inmemory | ||
filesystem: | ||
rootdirectory: /var/lib/registry | ||
delete: | ||
enabled: true | ||
auth: | ||
htpasswd: | ||
realm: basic-realm | ||
path: /var/lib/htpasswd | ||
http: | ||
addr: :5000 | ||
headers: | ||
X-Content-Type-Options: [nosniff] | ||
tls: | ||
certificate: /etc/pki/certs/tls.crt | ||
key: /etc/pki/certs/tls.key | ||
health: | ||
storagedriver: | ||
enabled: true | ||
interval: 10s | ||
threshold: 3 |
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,5 @@ | ||
FROM registry.access.redhat.com/ubi8:latest | ||
RUN dnf install -y httpd && dnf clean all -y | ||
COPY index.html /var/www/html | ||
RUN dnf install -y git && dnf clean all -y | ||
CMD ["/usr/sbin/httpd", "-DFOREGROUND"] |
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 @@ | ||
Hello World! |
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,4 @@ | ||
quay.io: | ||
tls-verify: true | ||
images-by-tag-regex: | ||
openshift-release-dev/ocp-release: ^4\.9\..*-x86_64$ |
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,11 @@ | ||
FROM local-registry.example.com/ubi8 | ||
|
||
# Update image and install httpd | ||
RUN yum install -y httpd && yum clean all -y | ||
|
||
# Expose the default httpd port 80 | ||
EXPOSE 80 | ||
|
||
# Run the httpd | ||
CMD ["/usr/sbin/httpd", "-DFOREGROUND"] | ||
|
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,11 @@ | ||
FROM registry.access.redhat.com/ubi_8 | ||
|
||
# Update image and install httpd | ||
RUN yum install -y httpd && yum clean all -y | ||
|
||
# Expose the default httpd port 80 | ||
EXPOSE 80 | ||
|
||
# Run the httpd | ||
CMD ["/usr/sbin/httpd", "-DFOREGROUND"] | ||
|
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,11 @@ | ||
FROM docker.io/library/fedora:sometag | ||
|
||
# Update image and install httpd | ||
RUN dnf install -y httpd && dnf clean all -y | ||
|
||
# Expose the default httpd port 80 | ||
EXPOSE 80 | ||
|
||
# Run the httpd | ||
CMD ["/usr/sbin/httpd", "-DFOREGROUND"] | ||
|
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,11 @@ | ||
FROM registry.access.redhat.com/ubi8 | ||
|
||
# Update image and install httpd | ||
RUN yum install -y htpd && yum clean all -y | ||
|
||
# Expose the default httpd port 80 | ||
EXPOSE 80 | ||
|
||
# Run the httpd | ||
CMD ["/usr/sbin/httpd", "-DFOREGROUND"] | ||
|
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,11 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
# Trying to pull a non-existing tag of Fedora official image | ||
container=$(buildah from docker.io/library/fedora:non-existing-tag) | ||
buildah run $container -- dnf install -y httpd; dnf clean all -y | ||
buildah config --cmd "httpd -DFOREGROUND" $container | ||
buildah config --port 80 $container | ||
buildah commit $container myhttpd | ||
buildah tag custom-httpd registry.example.com/custom-httpd:v0.0.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,24 @@ | ||
FROM docker.io/library/golang AS builder | ||
|
||
# Copy files for build | ||
RUN mkdir -p /go/src/students/models | ||
COPY go.mod main.go /go/src/students | ||
COPY models/main.go /go/src/students/models | ||
|
||
# Set the working directory | ||
WORKDIR /go/src/students | ||
|
||
# Download dependencies | ||
RUN go get -d -v ./... | ||
|
||
# Install the package | ||
RUN go build -v | ||
|
||
# Runtime image | ||
FROM registry.access.redhat.com/ubi8/ubi-minimal:latest as bin | ||
COPY --from=builder /go/src/students /usr/local/bin | ||
COPY entrypoint.sh / | ||
|
||
EXPOSE 8080 | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] |
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,14 @@ | ||
CREATE TABLE students ( | ||
id integer NOT NULL, | ||
firstname char(256) NOT NULL, | ||
middlename char(256) NOT NULL, | ||
lastname char(256) NOT NULL, | ||
class char(128) NOT NULL, | ||
course char(128) NOT NULL); | ||
|
||
INSERT INTO students (id, firstname, middlename, lastname, class, course) VALUES | ||
('10149', 'Frank', 'Vincent', 'Zappa', '3A', 'Composition'); | ||
|
||
ALTER TABLE students ADD PRIMARY KEY (id); | ||
|
||
|
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,9 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
if [ $# -eq 0 ]; then | ||
exec /usr/local/bin/students | ||
else | ||
exec $@ | ||
fi |
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,5 @@ | ||
module github.com/PacktPublishing/Podman-for-DevOps/Chapter10/students | ||
|
||
go 1.16 | ||
|
||
require github.com/lib/pq v1.10.4 // indirect |
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 @@ | ||
github.com/lib/pq v1.10.4 h1:SO9z7FRPzA03QhHKJrH5BXA6HU1rS4V2nIVrrNC1iYk= | ||
github.com/lib/pq v1.10.4/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= |
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,71 @@ | ||
package main | ||
|
||
import ( | ||
"database/sql" | ||
"encoding/json" | ||
"flag" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"os" | ||
|
||
"github.com/PacktPublishing/Podman-for-DevOps/Chapter10/students/models" | ||
|
||
_ "github.com/lib/pq" | ||
) | ||
|
||
func main() { | ||
|
||
var ( | ||
username string | ||
password string | ||
host string | ||
port string | ||
database string | ||
usage string | ||
) | ||
|
||
flag.StringVar(&username, "username", "admin", "Default database username") | ||
flag.StringVar(&password, "password", "password", "Default database password") | ||
flag.StringVar(&host, "host", "localhost", "Default host running the database") | ||
flag.StringVar(&port, "port", "5432", "Default database port") | ||
flag.StringVar(&database, "database", "students", "Default application database") | ||
flag.Usage = func() { | ||
fmt.Fprintf(flag.CommandLine.Output(), usage, os.Args[0]) | ||
flag.PrintDefaults() | ||
} | ||
flag.Parse() | ||
|
||
connString := "postgres://" + username + ":" + password + "@" + host + ":" + port + "/" + database + "?sslmode=disable" | ||
log.Printf("Connecting to host %s:%s, database %s", host, port, database) | ||
|
||
var err error | ||
models.DB, err = sql.Open("postgres", connString) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
http.HandleFunc("/students", getStudents) | ||
|
||
if err := http.ListenAndServe(":8080", nil); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
} | ||
|
||
// getStudents is a HTTP GET method to print a full list of the students in JSON encoding | ||
func getStudents(w http.ResponseWriter, r *http.Request) { | ||
studentsInfo, err := models.GetStudents() | ||
if err != nil { | ||
http.Error(w, http.StatusText(500), 500) | ||
return | ||
} | ||
|
||
for _, std := range studentsInfo { | ||
s, err := json.Marshal(std) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Fprintf(w, "%s", string(s)) | ||
} | ||
} |
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,53 @@ | ||
package models | ||
|
||
import ( | ||
"database/sql" | ||
"strings" | ||
) | ||
|
||
var DB *sql.DB | ||
|
||
type Student struct { | ||
Id int | ||
FirstName string | ||
MiddleName string | ||
LastName string | ||
Class string | ||
Course string | ||
} | ||
|
||
func GetStudents() ([]Student, error) { | ||
rows, err := DB.Query("SELECT * from students") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
defer rows.Close() | ||
|
||
var students []Student | ||
|
||
for rows.Next() { | ||
var student Student | ||
err := rows.Scan(&student.Id, &student.FirstName, &student.MiddleName, &student.LastName, &student.Class, &student.Course) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Trim uncessary spaces from string fields | ||
student.FirstName = strings.TrimSpace(student.FirstName) | ||
student.MiddleName = strings.TrimSpace(student.MiddleName) | ||
student.LastName = strings.TrimSpace(student.LastName) | ||
student.Class = strings.TrimSpace(student.Class) | ||
student.Course = strings.TrimSpace(student.Course) | ||
|
||
// Append the struct to the slice of students | ||
students = append(students, student) | ||
} | ||
|
||
err = rows.Err() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return students, nil | ||
} |