goblog

module
v0.0.0-...-19284bb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2020 License: MIT

README

goblog

Code samples for the Go microservice blog series

Changelog

  • 2019-07-27: Total rewrite of Go code, including introducing Makefiles for build and a docker-compose file for deployment on Docker Swarm.
Some URLs to remember

Turbine stream URL: http://192.168.99.100:8282/turbine.stream?cluster=swarm Hystrix stream URL: http://accountservice:8181/hystrix.stream?cluster=swarm

Make sure Turbine doesn't crash on startup due to AMQ connection problem.

Setting up Docker Swarm cluster
docker-machine create --driver virtualbox --virtualbox-cpu-count 4 --virtualbox-memory 6000 --virtualbox-disk-size 30000 swarm-manager-0
eval "$(docker-machine env swarm-manager-0)"
docker swarm init --advertise-addr $(docker-machine ip swarm-manager-0)
docker network create --driver overlay my_network
Adding a worker node
docker swarm join --token SWMTKN-1-5njothki0tww7gestuh309qgrnr6r357phlsn7ue0r8qmlqnla-181tl1rfou16vv3e7nxrk4ra3 192.168.99.100:2377
Building

You need go 1.13 or later installed on your system to build from source.

Builds are performed using Makefile(s). In the root /goblog folder:

make build

One can also run all tests, format code using makefile targets.

Deploying

Deploy using:

make deploy

The make target uses docker stack deploy behind the scenes.

Nice to haves

Here's some minor stuff worth remembering.

Running the CockroachDB client

Find a container running the cockroachdb/cockroach container using docker ps and note the container ID. Then we'll use docker exec to launch the SQL CLI:

> docker exec -it 10f4b6c727f8 ./cockroach sql --insecure
Create user and database for Cockroach

(this is possibly broken, from part 16 onwards the initial DB setup is performed using the docker stack)

Originally from: https://github.com/cockroachdb/cockroach/issues/19826#issuecomment-358360851

DROP USER IF EXISTS cockroach; \
DROP DATABASE IF EXISTS account CASCADE; \
CREATE DATABASE IF NOT EXISTS account; \
CREATE USER cockroach WITH PASSWORD 'password'; \
GRANT ALL ON DATABASE account TO cockroach;

// DROP USER IF EXISTS cockroach; DROP DATABASE IF EXISTS account CASCADE; CREATE DATABASE IF NOT EXISTS account; CREATE USER cockroach WITH PASSWORD 'password'; GRANT ALL ON DATABASE account TO cockroach;

BUILD THE KEYSTORE To use encrypted properties later on, we’ll configure the config server with a self-signed certificate. (You’ll need to have keytool on your PATH).

In the /goblog/support/config-server/ folder, run:

keytool -genkeypair -alias goblogkey -keyalg RSA -dname "CN=Go Blog,OU=Unit,O=Organization,L=City,S=State,C=SE" -keypass changeme -keystore server.jks -storepass letmein -validity 730

This should create server.jks. Feel free to modify any properties/passwords, just remember to update application.yml accordingly!

shell sudo sed -i "s|EXTRA_ARGS='|EXTRA_ARGS='--registry-mirror=https://www.daocloud.io/mirror |g" /var/lib/boot2docker/profile

docker-machine create -d virtualbox
--engine-env HTTP_PROXY=http://example.com:8080
--engine-env HTTPS_PROXY=https://example.com:8080
--engine-env NO_PROXY=example2.com
default

Directories

Path Synopsis
cmd
common module
dataservice module
cmd
internal/app/dbclient/mock_dbclient
Package mock_dbclient is a generated GoMock package.
Package mock_dbclient is a generated GoMock package.
ws
* The MIT License (MIT) Copyright (c) 2017 ErikL Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* The MIT License (MIT) Copyright (c) 2017 ErikL Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
imageservice module
cmd
cmd/imageservice
* The MIT License (MIT) Copyright (c) 2016 Callista Enterprise Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* The MIT License (MIT) Copyright (c) 2016 Callista Enterprise Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
vipservice module
cmd
cmd/vipservice
* The MIT License (MIT) Copyright (c) 2016 Callista Enterprise Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* The MIT License (MIT) Copyright (c) 2016 Callista Enterprise Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL