Skip to content

Instantly share code, notes, and snippets.

@timpamungkasudemy
Last active June 13, 2024 15:54
Show Gist options
  • Save timpamungkasudemy/e922c005c65a65e848521b12e5dbb86d to your computer and use it in GitHub Desktop.
Save timpamungkasudemy/e922c005c65a65e848521b12e5dbb86d to your computer and use it in GitHub Desktop.

Download Tools for Running Sample Code

For Beginner

If you need to be more familiar with Spring REST API and Spring Kafka, go here:

Run Sample Code with Docker

The following docker tips might be handy in this course. Please note that this course is NOT focusing on docker, so this is just a supplementary, basic tips.

Download the docker scripts (docker-compose-xxx.yml) from lecture Resource & References.
Open terminal / command prompt, then go to directory where docker-compose.yml located

Docker-compose Commands

IMPORTANT: Before start docker-compose command, make sure docker-compose.yml is in current directory.
Alternatively, you can point the file to use, by adding -f parameter,for example like this :

docker-compose -f /path/to/my/file.yml ...

Click to expand the reference

docker-compose up -d Create all containers and start them.

docker-compose up --no-start Create all containers, without start them.

docker-compose start Start all containers.

docker-compose stop Stop all running containers.

docker-compose down Stop all containers and remove them.

docker-compose ps List all running containers.

docker-compose ps -a List all containers.

docker-compose logs --tail 200 -f See logs from all containers.

docker-compose logs --tail 200 -f [container name] See logs from specific container.

docker-compose [command] --help Display additional information for [command]

Docker Commands

Run this commands from terminal / console. For Linux, make sure you have root or sudo access.

Click to expand the reference

docker ps List running containers.

docker ps -a List all containers (running and stop).

docker container create Create a container, not running it. See official docker documentation for further reference.

docker container start [container-name or container-id] Start an existing container. See official docker documentation for further reference.

docker container stop [container-name or container-id] Stop a running container.

docker container rm [container-name or container-id] Remove container.

docker pull [image-name] Pull a docker image from repository with default tag (latest)

docker image ls List docker images in your machine.

docker image rm [image-id] Remove docker image in your machine. Docker image can take quite amount of hard-drive, so you might want to cleanup unused images. Image to be removed must not be used in any container, even if the container is stopped.

docker [command] --help Display additional information for [command]

Microservice Chassis

Java Sample Framework

Go Sample Framework

.NET Sample Framework

Services Communication

Communication Error Handling

Organizing Source Code

Data Transaction Across Services

Event Sourcing

API Gateway

Prepare For Production

Microservice on Google Cloud

Documentation

Spring Google Cloud official documentation

How to

First, you must create and authenticate to google cloud.
Follow steps on google documentation.

The, build and upload your image. Follow the following steps:

  1. Build docker image. Open terminal, go to google-cloud java project home, and run
#> ./gradlew bootBuildImage --imageName=ms-pattern/spring-google-cloud:latest
  1. Tag the docker image. Change the [parameter] according to your environment.
#> docker tag [docker-image-name]:[docker-image-tag] \
   [google-cloud-region]-docker.pkg.dev/[google-project-name]/[artifact-registry-name]/[docker-image-name]:[docker-image-tag]

Example:

#> docker tag ms-pattern/spring-google-cloud:latest \
   asia-southeast2-docker.pkg.dev/timpamungkas-google/docker-artifact-registry/spring-google-cloud:latest
  1. Push the tagged docker image. Change the [parameter] according to your environment.
#> docker push [google-cloud-region]-docker.pkg.dev/[google-project-name]/[artifact-registry-name]/[docker-image-name]:[docker-image-tag]

Example

#> docker push asia-southeast2-docker.pkg.dev/timpamungkas-google/docker-artifact-registry/spring-google-cloud:latest

Further reference on google cloud documentation

Kubernetes Configuration

Kubernetes service account

Service Mesh

Install Cloud Trace

See reference here and here.

Example

#> ./asmcli install \
  --project_id timpamungkas-google \
  --cluster_name cluster-course-with-mesh \
  --cluster_location asia-southeast2-a \
  --enable_all \
  --output_dir ./asmcli-output \
  --custom_overlay anthos-trace.yml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment