Bcfm-study-case - A simple http server using the Echo library in Go language

Task 1 Hakkında

Burada Go dilinde Echo kütüphanesini kullanarak basit bir http serverı yazdım.

Sadece 2 adet endpoint var.; Get istekleri olduklari icin browser ile istekler atarak response'lara bakalım;

GET /

Alt text

GET /temperature?city=

Alt text

Temperature bilgisi icin bir Weather API kullandım, orada gerekli olan api keyi containeri ayağa kaldırırken environment variable olarak veriyoruz, ikinci kısımda değineceğim.

Task 2 Hakkında

Burada Go ile yazdığım uygulamamı containerize etmeye çalıştım.

Base image olarak dockerhub da bulduğum golang:1.17 image'ını kullanacağım.

FROM golang:1.17

Container içindeyken ana çalışma dizini olarak /app klasörünü seçtim.

WORKDIR /app

Projenin dependencylerini indirmek için go mod ve go sum dosyalarımızı içeriye kopyalıyoruz.

COPY go.mod go.sum ./
RUN go mod download

Bu sefer proje dizinindeki dosyaların hepsini kodluyoruz. (Hatırladığım kadarıyla burada multi stage build yapmış oluyoruz. Daha performanslı bir yol oluyor. Dependencylerden biri değişse bile koca projeyi yeniden build etmiyordu biz yeniden build işlemi yaptığımızda.)

COPY . .

Daha sonra dışarıdan erişebilmemiz için http portunu açıyoruz.

EXPOSE 8080

Dependencylerimizi indirik ve projenin bütün dosyaları dizinde mevcut. Artık projeyi build edip giriş komutunu belirleyebiliriz. main adı altında build edip giriş komutuna ./main komutunu veriyoruz.

RUN go build -o main cmd/main/main.go
CMD ./main

Şimdi Dockerfile'ımız hazır olduğuna göre projemizi build edebiliriz. Projemizi bcfmstudycase tagi ile build ediyoruz.

docker build -t bcfmstudycase .

Daha sonra docker run ile build ettigimiz image'ı ayağa kaldırıyoruz. Ben run ederken kendi APIKEY değerimi environment variable olarak veriyorum.

docker run -p 8080:8080 -e APIKEY=XXXXXXXXXXXXXX bcfmstudycase

Ve sonuç ;

Alt text

Task 3 Hakkında

Daha önce birkaç kez adını duymuş olduğum bir CI/CD platformu olan Travis ile bir deployment pipeline kurmaya çalıştım. Her code pushundan sonra yeni code yapısı ile beraber tekrar build edip Dockerhub'a pushlayıp AWS Elasticbeanstalk ile beraber otomatik deployment yapacak şekilde bir sistem kurmak istemiştim fakat aradaki bağı kuramadım. Github hesabımı Travis ile eşleştirip Travis konfigürasyon dosyasını oluşturdum fakat Travis tarafında yeni buildler görülmüyordu.

Daha sonra direkt olarak bir AWS EC2 instance alarak onun üzerine docker kurarak containerimi manuel olarak çalıştırmayı düşündüm ve bu şekilde gerçekleştirdim.

Aşağıdaki komut dizisi ile githubdan projeyi EC2 instance'ına klonlayıp, build alıp lokalde run ettiğimiz gibi gerekli port mappingleri yaparak run ettim.

git clone https://github.com/canergulay/bcfm-study-case
cd bcfm-study-case
docker build -t bcfmstudycase .
docker run -p 8080:8080 -e APIKEY=XXXXXXX bcfmstudycase

Burada daha önce aşina olmadığım bir problem ile karşılaştım ; Port mappingin yapılmasına rağmen browserden public ip ile get isteği attığımda port connection refused hatası alıyordum, biraz araştırınca gördüm ki security groups ayarı yapılarak AWS tarafında ayrıca bir port konfigurasyonu yapmamız gerekiyormuş. Onunla beraber 8080 portundan istek kabul etmeye başladı.

GET / http://ec2-54-245-169-31.us-west-2.compute.amazonaws.com:8080/

GET /temperature - http://ec2-54-245-169-31.us-west-2.compute.amazonaws.com:8080/temperature?city=istanbul

Owner
Caner Gülay
Backend & Mobile developer. constant learner. self educator.
Caner Gülay
Similar Resources

Genetic algorithms using Golang Generics

Package genetic Package genetic implements genetic algorithms using Golang's Gen

Sep 23, 2022

Genetic Algorithms library written in Go / golang

Description Genetic Algorithms for Go/Golang Install $ go install git://github.com/thoj/go-galib.git Compiling examples: $ git clone git://github.com

Sep 27, 2022

Gorgonia is a library that helps facilitate machine learning in Go.

Gorgonia is a library that helps facilitate machine learning in Go.

Gorgonia is a library that helps facilitate machine learning in Go. Write and evaluate mathematical equations involving multidimensional arrays easily

Dec 30, 2022

onnx-go gives the ability to import a pre-trained neural network within Go without being linked to a framework or library.

onnx-go gives the ability to import a pre-trained neural network within Go without being linked to a framework or library.

This is a Go Interface to Open Neural Network Exchange (ONNX). Overview onnx-go contains primitives to decode a onnx binary model into a computation b

Dec 24, 2022

A neural network library built in Go

go-mind A neural network library built in Go. Usage import "github.com/stevenmiller888/go-mind" m := mind.New(0.7, 10000, 3, "sigmoid") m.Learn([][]

Aug 27, 2022

Gorgonia is a library that helps facilitate machine learning in Go.

Gorgonia is a library that helps facilitate machine learning in Go.

Gorgonia is a library that helps facilitate machine learning in Go. Write and evaluate mathematical equations involving multidimensional arrays easily

Dec 27, 2022

A Go library implementing an FST (finite state transducer)

A Go library implementing an FST (finite state transducer)

vellum A Go library implementing an FST (finite state transducer) capable of: mapping between keys ([]byte) and a value (uint64) enumerating keys in l

Jan 8, 2023

A High-level Machine Learning Library for Go

A High-level Machine Learning Library for Go

Overview Goro is a high-level machine learning library for Go built on Gorgonia. It aims to have the same feel as Keras. Usage import ( . "github.

Nov 20, 2022

Library for multi-armed bandit selection strategies, including efficient deterministic implementations of Thompson sampling and epsilon-greedy.

Library for multi-armed bandit selection strategies, including efficient deterministic implementations of Thompson sampling and epsilon-greedy.

Mab Multi-Armed Bandits Go Library Description Installation Usage Creating a bandit and selecting arms Numerical integration with numint Documentation

Jan 2, 2023
Self-contained Machine Learning and Natural Language Processing library in Go
Self-contained Machine Learning and Natural Language Processing library in Go

Self-contained Machine Learning and Natural Language Processing library in Go

Jan 8, 2023
A simple OCR API server, seriously easy to be deployed by Docker, on Heroku as well
A simple OCR API server, seriously easy to be deployed by Docker, on Heroku as well

ocrserver Simple OCR server, as a small working sample for gosseract. Try now here https://ocr-example.herokuapp.com/, and deploy your own now. Deploy

Dec 28, 2022
Go package for OCR (Optical Character Recognition), by using Tesseract C++ library

gosseract OCR Golang OCR package, by using Tesseract C++ library. OCR Server Do you just want OCR server, or see the working example of this package?

Jan 3, 2023
Simple gc using integer vectors to simulate

gcint Simple gc using integer vectors to simulate Iterate primarily over what should be the shorter vector (readers) removing unused references in fro

Nov 24, 2021
A program that generates a folder structure with challenges and projects for mastering a programming language.

Challenge Generator A program that generates a folder structure with challenges and projects for mastering a programming language. Explore the docs »

Aug 31, 2022
GoPlus - The Go+ language for engineering, STEM education, and data science

The Go+ language for engineering, STEM education, and data science Summary about Go+ What are mainly impressions about Go+? A static typed language. F

Jan 8, 2023
Spice.ai is an open source, portable runtime for training and using deep learning on time series data.
Spice.ai is an open source, portable runtime for training and using deep learning on time series data.

Spice.ai Spice.ai is an open source, portable runtime for training and using deep learning on time series data. ⚠️ DEVELOPER PREVIEW ONLY Spice.ai is

Dec 15, 2022
Incentivized AI Training Casino using ISCP for the Agri-D Hackaton!
Incentivized AI Training Casino using ISCP for the Agri-D Hackaton!

Welcome to the Wasp repository! Wasp is a node software developed by the IOTA Foundation to run the IOTA Smart Contract Protocol (ISCP in short) on to

May 15, 2022
Advent of Code 2016 in Go using only GitHub Copilot

Advent of Gopilot Solutions to Advent of Code 2016 in Go using only GitHub Copilot. "Rules" The idea is to have GitHub Copilot generate all the actual

Nov 16, 2021
face detction/recognization golang lib using tensorflow facenet
face detction/recognization golang lib using tensorflow facenet

Golang lib for detect/recognize by tensorflow facenet Prerequest libtensorfow 1.x Follow the instruction Install TensorFlow for C facenet tenorflow sa

Sep 23, 2022