Cloud-oriented Life

Cloud Native Technology Improves Lives

Use Foreign Data Wrappers in Rails

Foreign Data Wrappers is a fantastic feature of PostgreSQL that allows you to query against external data sources. The external data source is not just a different Postgres database - it could be anything as long as the appropriate extension is available for that particular data source. You can make it work with MySQL, Redis, MongoDB, and even Kafka, so the flexibility is quite impressive. Nevertheless, let’s focus on Postgres-to-Postgres integration, which is available out of the box.

Read more »

Diesel

Diesel is a Safe, Extensible ORM and Query Builder for Rust.

Diesel is the most productive way to interact with databases in Rust because of its safe and composable abstractions over queries.

For this guide, we’re going to walk through some simple examples for each of the pieces of CRUD, which stands for “Create Read Update Delete”. Each step in this guide will build on the previous, and is meant to be followed along.

Read more »

Docker FAQs

Modify container by config file

Each Docker container has a set of config files associated with it. The parameters of that container, such as Image, Port mapping, would be specified in that file.

The config file is a json file at the location /var/lib/docker/containers/<Container ID>/config.v2.json.

1
2
3
4
5
6
7
8
9
10
11
12
13
# Get container id.
$ docker ps

# Or get container id.
$ docker inspect <Container Short ID>

# Stop container
$ docker stop <Container Short ID>

$ vi /var/lib/docker/containers/<Container ID>/config.v2.json

# Start container
$ docker start <Container Short ID>

After stopping the container, the config.v2.json file can be edited to update the corresponding entry for Ports and NetworkSettings. The PortBindings entry in hostconfig.json file is also updated.

After making the changes in config files, Docker service is restarted and container is started.

See Docker - change container configuration in 4 ways - https://bobcares.com/blog/docker-change-container-configuration/ to learn more.

References

[1] Empowering App Development for Developers | Docker - https://www.docker.com/

Get into the Docker VM

When using Docker Desktop for Mac and Windows | Docker - https://www.docker.com/products/docker-desktop, you’re actually using a tiny (custom) Alpine Linux running in a special xhyve VM on macOS or Windows. There’s so much cool stuff happening, you’re meant to forget it’s still running on a Linux kernel.

Read more »

Docker Compose FAQs

ImportError: No module named ‘requests.packages.urllib3’

1
2
3
4
# CentOS 7.x
$ docker-compose up
...
ImportError: No module named 'requests.packages.urllib3'

Install specific version of requests.

1
2
3
$ sudo pip install requests urllib3 pyOpenSSL --force --upgrade

$ sudo pip install --upgrade --force-reinstall 'requests==2.6.0'

References

References

[1] Microservices in Go: REST APIs (Part 4) - OpenAPI 3 and Swagger UI - https://mariocarrion.com/2021/05/02/golang-microservices-rest-api-openapi3-swagger-ui.html

[2] REST Servers in Go: Part 4 - using OpenAPI and Swagger - Eli Bendersky’s website - https://eli.thegreenplace.net/2021/rest-servers-in-go-part-4-using-openapi-and-swagger/

[3] Go, Swagger, and Open API. Documenting Go REST services with… | by Pagis | May, 2021 | Level Up Coding - https://levelup.gitconnected.com/go-swagger-and-open-api-e6b6ea4ce48f

Swagger Open API Specification 2.0 and 3.0 in Go | by Kecci Kun | Medium - https://kecci.medium.com/swagger-open-api-specification-2-0-and-3-0-in-go-c1f05b51a595

deepmap/oapi-codegen: Generate Go client and server boilerplate from OpenAPI 3 specifications - https://github.com/deepmap/oapi-codegen

getkin/kin-openapi: OpenAPI 3.0 implementation for Go (parsing, converting, validation, and more) - https://github.com/getkin/kin-openapi

go-swagger/go-swagger: Swagger 2.0 implementation for go - https://github.com/go-swagger/go-swagger

Swagger 2.0 | Primer · GitBook - https://goswagger.io/

swaggo/swag: Automatically generate RESTful API documentation with Swagger 2.0 for Go. - https://github.com/swaggo/swag

Bitnami Redis with Docker and Docker Compose

Bitnami makes it easy to get your favorite open source software up and running on any platform, including your laptop, Kubernetes and all the major clouds. In addition to popular community offerings, Bitnami, now part of VMware, provides IT organizations with an enterprise offering that is secure, compliant, continuously maintained and customizable to your organizational policies.

Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache, and message broker. Redis provides data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes, and streams. Redis has built-in replication, Lua scripting, LRU eviction, transactions, and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.

Read more »
0%