Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
ffa811f
Modify the Dockerfile to be optimized
Los-merengue Apr 18, 2023
6ba3541
Update the way the Dockerfile is optimized
Los-merengue Apr 18, 2023
863c98d
Modify the README.md to update the Optimizing Dcokerfile
Los-merengue Apr 18, 2023
86c8425
Modify the README.md to update the Optimizing Dcokerfile
Los-merengue Apr 18, 2023
74fe15d
Modify the README.md to update the Optimizing Dcokerfile
Los-merengue Apr 18, 2023
1d27aa5
Modify the README.md to update the Optimizing Dcokerfile
Los-merengue Apr 18, 2023
62b032b
Modify the Dockerfile
Los-merengue Apr 18, 2023
788dd84
Add the README.md for the Multistage build
Los-merengue Apr 18, 2023
4c9ca83
Update the README.md for the multistage explanation
Los-merengue Apr 18, 2023
b057f4f
Update the README.md for the multistage explanation
Los-merengue Apr 18, 2023
39ffb8e
Update the README.md for the multistage explanation
Los-merengue Apr 18, 2023
f0ab91e
Update the README.md for the multistage reason
Los-merengue Apr 18, 2023
d3902ba
Update on README.md
Los-merengue Apr 18, 2023
a10a1c4
Modify te=he README.md
Los-merengue Apr 18, 2023
8b24f4c
Modify the README.md for Task1
Los-merengue Apr 18, 2023
51b306a
Updated the README.md for task1
Los-merengue Apr 18, 2023
a238e64
init
Los-merengue Apr 19, 2023
486b053
Added the service-alpha
Los-merengue Apr 19, 2023
988fa65
Added the vault-resources module
Los-merengue Apr 19, 2023
f2d861f
modify the name of the module
Los-merengue Apr 19, 2023
d3e1233
Modify the main of the module
Los-merengue Apr 19, 2023
c94d287
Edited the vault-resources file
Los-merengue Apr 19, 2023
2b9e034
Modify the service-alpha module
Los-merengue Apr 19, 2023
378e249
Added comment to the main.tf file
Los-merengue Apr 19, 2023
4a81ec6
Updated the README.md of task2
Los-merengue Apr 19, 2023
638cb21
Updated the README.md of task2
Los-merengue Apr 19, 2023
00cefb8
modify the userpass resources
Los-merengue Apr 19, 2023
67ca652
Add `image.png` via upload
Los-merengue Apr 19, 2023
88799a5
edit the task1 docker
Los-merengue Apr 19, 2023
90744da
Merge branch 'interviewee' of https://github.com/Los-merengue/schwarz…
Los-merengue Apr 19, 2023
da9e56f
Added 'image.png'
Los-merengue Apr 19, 2023
e324ff4
Added 'image.png'
Los-merengue Apr 19, 2023
97bc4dd
Added 'image.png'
Los-merengue Apr 19, 2023
f8a5e04
Added 'image.png'
Los-merengue Apr 19, 2023
f0bd0a2
Added 'image.png'
Los-merengue Apr 19, 2023
543e37f
Added 'image.png'
Los-merengue Apr 19, 2023
2ffefa5
Added 'image.png'
Los-merengue Apr 19, 2023
4783f5b
Added 'image.png'
Los-merengue Apr 19, 2023
b017cd1
'URL for v1.0.0'
Los-merengue Apr 19, 2023
2418cc0
Docker image URL v1.0.0'
Los-merengue Apr 19, 2023
5b189dc
Docker image URL v1.0.0' and 'latest'
Los-merengue Apr 19, 2023
0ebd384
Added 'image.png' to resize
Los-merengue Apr 19, 2023
bf3f628
Added 'image.png' to resize
Los-merengue Apr 19, 2023
54fe16e
Added 'image.png' to resize
Los-merengue Apr 19, 2023
db690eb
Added 'image.png' to resize
Los-merengue Apr 19, 2023
15e9cb1
Added 'image.png' to resize
Los-merengue Apr 19, 2023
6e5d40e
Added 'image2' for docker images
Los-merengue Apr 19, 2023
d05e2bb
Added the path to image2 in README
Los-merengue Apr 19, 2023
7889ff4
Added the path to image2 in README
Los-merengue Apr 19, 2023
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
20 changes: 17 additions & 3 deletions task1_docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
FROM golang:1.19
# Build Stage
FROM golang:1.19 AS build
WORKDIR /app
COPY . .
COPY go.mod ./
RUN go mod download
RUN go build -o /hello_world
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o /hello_world

# Production Stage
FROM scratch
COPY --from=build /hello_world /hello_world
ENTRYPOINT ["/hello_world"]


#FROM golang:1.19
#WORKDIR /app
#COPY . .
#RUN go mod download
#RUN go build -o /hello_world
#ENTRYPOINT ["/hello_world"]
72 changes: 69 additions & 3 deletions task1_docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,90 @@

### 1. Optimize Dockerfile (make it more lightweight)
```
Type here what was done...
To optimize it, it means I have to make the Dockerfile as lightweight
as possible and the benefits to this is to reduce the attack area and
improve the security of the overall application. The methods implemented involves:

- Using a specific base image that matches the requirements of the
application in production

- when using the COPY command, I made sure I copied the necessary files
for the building and running of the application

- Combining the RUN command instead of using multiple RUN commands,
becasue these commands add an extra layer to the application

- Finally using a multi-stage build

```

### 2. Do a multistage build
```
Type here what was done...

To create a multistage build technically mean creating a more than one
build so as to keep the Dockerfile optimized, easy to read and maintain.
This is so because most times developers uses different Dockerfile for
build and production. To achieve this this is what i did:
The multistage build consist of two stages, where each is defined with
its own FROM statement

- Build Stage

In this stage, I use an official Golang image as the base image and
give it an alias "build" ('FROM golang:1.19 AS build).
I set the working directory to "./app", copy the go.mod files to
the container, and download the Go module dependencies using the "go
mod download".
I then copy the rest of the application code to the container and build
it using the "CGO_ENABLED=0 GOOS=linux go build" command with the
necessary flags to produce a statically linked binary executable ('/
hello_world').
Finally an optional case of using the strip command. The strip command
can be used to remove the debug information from the executable, this
like i said is optional and not necessary.

- Production Stage

In this stage, I will start with a minimal 'scratch' base image, which
contains no files or dependencies.
I copied the '/hello_world' binary executable from the 'build' stage
using the 'COPY --from=build' command which copies the file from the
'build' stage to the current stage.
Finally, I will set the entry point to '/hello_world', which specifies
the command to run when the container starts
```

### 3. Build, run and open in browser
```
Type here the command you used to build and run the container...
To do this we will run the following command

- docker build -t go_app .
- docker run -p 8060:8060 go_app

To open in browser, I will access http:/localhost:8060/helloworld

```

![](image.png)


### 4. Tag it with :v1.0.0 and :latest and push the image to your DockerHub or Github Packages repository
```
Type here the public image URL
For (:v1.0.0):
- docker build -t galactican/go_app:v1.0.0 .
- docker push galactican/go_app:v1.0.0

```
[Docker image for v1.0.0](https://hub.docker.com/layers/galactican/go_app/v1.0.0/images/sha256:4805a5a50105f82ec9563b118757084608a565760e64281bac93f8c3370882cd)

```
For (:latest)
- docker build -t galactican/go_app:latest .
- docker push galactican/go_app:latest

```
[Docker image for :latest](https://hub.docker.com/layers/galactican/go_app/latest/images/sha256:4805a5a50105f82ec9563b118757084608a565760e64281bac93f8c3370882cd)


![](image2.png)
Binary file added task1_docker/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added task1_docker/image2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 11 additions & 2 deletions task2_vault/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,23 @@
Look for TODO comment in the tf config. Don't modify existing resources.\
Check if the container is able to read and print the secret or still produces errors: `docker logs -f service-alpha`.
```
Type here what was done...

I created a new policy called service-alpha-policy as showned in the script.
The policy explains that the created secrets engine will have a read permission.
Meaning that every key implemented in that directory can be read when they are required
```

### 2. Split the terraform config into 2 modules.
One for building/deploying the service, another for managing vault resources.\
Use variables.
```
Type here what was done...

I splitted the configuration into two modules, where one of the modules 'service-alpha' is
responsible for building and deploying the service alpha container

The other module 'vault-resources' is responsible for managing resources meant by vault which
may include 'vault_generic_secret, vault_auth_backend, vault_policy, and vault_userpass_user'

Both of these modules can then be used within the 'main.tf' and reference appropriately

```
35 changes: 32 additions & 3 deletions task2_vault/tf/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# This is the main terraform script used for implemeneting the module created

module "service-alpha" {
source = "./service-alpha"
}

module "vault" {
source = "./vault"
}



/**
terraform {
required_version = ">= 1.1.0"

Expand Down Expand Up @@ -47,10 +60,24 @@ resource "vault_auth_backend" "userpass" {

# TODO: Add missing users and policies

# policy for the service-alpha container
resource "vault_policy" "service-alpha-policy" {
name = "service-alpha-policy"
policy = <<EOT
path "secret/alpha" {
capabilities = ["read"]
}
EOT
}




# user with the above policy
resource "vault_userpass_user" "service-account" {
username = "interviewee"
password = "pass99"
policies = [
vault_policy.service-alpha-policy.name
]
}

###############################
# Build and run service-alpha
Expand Down Expand Up @@ -79,3 +106,5 @@ resource "docker_container" "service-alpha" {
name = "task2_vault_net_a"
}
}

**/
39 changes: 39 additions & 0 deletions task2_vault/tf/service-alpha.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This module is responsible for building and deploying the service-alpha container.

terraform {
required_version = ">= 1.1.0"

required_providers {
docker = {
source = "kreuzwerker/docker"
version = "3.0.2"
}
}
}

# Build and run service-alpha
resource "docker_image" "service-alpha" {
name = "service-alpha"

build {
context = "../services/alpha"
tag = ["service-alpha"]
}
triggers = {
dir_sha1 = sha1(join("", [for f in fileset(path.module, "../services/alpha/*") : filesha1(f)]))
}
}

resource "docker_container" "service-alpha" {
image = docker_image.service-alpha.image_id
name = "service-alpha"

env = [
"VAULT_ADDR=http://vault:8200",
"VAULT_USERNAME=service-account-1",
"VAULT_PASSWORD=pass99",
]
networks_advanced {
name = "task2_vault_net_a"
}
}
54 changes: 54 additions & 0 deletions task2_vault/tf/vault-resources.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# This module is reponsible for managing service in vault that is required by service-alpha

terraform {
required_version = ">= 1.1.0"

required_providers {
vault = {
version = "3.14.0"
}
}
}

# Connect to vault server
# (deployed by docker-compose)
provider "vault" {
address = "http://localhost:8200"
token = "f23612cf-824d-4206-9e94-e31a6dc8ee8d"
}

# This secret must be read by the service
resource "vault_generic_secret" "alpha" {
path = "secret/alpha"
data_json = <<EOT
{
"smiling_face": "( ͡° ͜ʖ ͡°)",
"bear": "ʕ•ᴥ•ʔ"
}
EOT
}

# Enable user-pass auth method
resource "vault_auth_backend" "userpass" {
type = "userpass"
}

# policy for the service-alpha container
resource "vault_policy" "service-alpha-policy" {
name = "service-alpha-policy"
policy = <<EOT
path "secret/alpha" {
capabilities = ["read"]
}
EOT
}

# user with the above policy
resource "vault_userpass_user" "service-account" {
username = "service-account-1"
password = "pass99"
policies = [
vault_policy.service-alpha-policy.name
]
}