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

Containerize Go-helloworld #113

Closed
wants to merge 4 commits into from
Closed
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
147 changes: 147 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,153 @@
## originally provided ##
.env/
.venv/
.vagrant/
.myvenv/
__pycache__/
.vagrant/

## newly added##

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

*.code-workspace

*.cfg

settings.json

.DS_Store

*.parquet

*.crc

_SUCCESS
11 changes: 11 additions & 0 deletions exercises/go-helloworld/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM golang:alpine

WORKDIR /go/src/app

ADD . .

RUN go mod init && go build -o helloworld

EXPOSE 6112

CMD ["./helloworld"]
2 changes: 1 addition & 1 deletion exercises/go-helloworld/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ func helloWorld(w http.ResponseWriter, r *http.Request){

func main() {
http.HandleFunc("/", helloWorld)
http.ListenAndServe(":6111", nil)
http.ListenAndServe(":6112", nil)
}
10 changes: 10 additions & 0 deletions exercises/python-helloworld/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:3.8
LABEL maintainer="Thitiwat Watanajaturaporn"

COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt

# command to run on a container
CMD ["python", "app.py"]

37 changes: 37 additions & 0 deletions exercises/python-helloworld/app.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
from flask import Flask
import json
import logging

app = Flask(__name__)

@app.route("/status")
def healthcheck():
response = app.response_class(
response=json.dumps({"result": "OK - Healthy"}),
status=200,
mimetype="application/json"
)
## log line
app.logger.info('Status request successfull')
return response

@app.route("/metrics")
def metrics():
response = app.response_class(
response=json.dumps({
"status": "success",
"code": 0,
"data": {
"userCount": 140,
"userCountActive": 23
}
}),
status=200,
mimetype="application/json"
)
## log line
app.logger.info('Metrics request successfull')
return response


@app.route("/")
def hello():
# Logging a custom message
app.logger.info("Main request successfull")
return "Hello World!"

if __name__ == "__main__":
# Stream logs to a file, and set the default log level to DEBUG
logging.basicConfig(filename='app.log',level=logging.DEBUG)
app.run(host='0.0.0.0')