Dimas Maulana

Dimas Maulana

Developer

Welcome to my website! I am a developer with a current focus on React and Go. My experience encompasses both front-end and back-end development, enabling me to design and develop seamless and efficient applications.

Building a Go Application With Docker: Optimized Dockerfile

In this article, we will walk through the creation of an optimized Dockerfile for building and running a Go application. This Dockerfile will focus on building only the binary of the Go application, resulting in a smaller and more efficient Docker image.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
## Dockerfile for Building a Go Application

```Dockerfile
# Stage 1: Build the Go Binary
FROM golang:1.17 as builder

# Set the working directory inside the container
WORKDIR /app

# Copy the Go application source code into the container
COPY . .

# Set environment variables
ENV CGO_ENABLED=0

# Fetch dependencies and build the Go binary
RUN go get -d -v ./...
RUN go build -o /tmp/api-server .

# Stage 2: Create a minimal runtime image
FROM scratch

# Copy the binary from the builder stage into the minimal image
COPY --from=builder /tmp/api-server /usr/bin/api-server

# Define the command to run when the container starts
CMD ["api-server", "start"]

In this Dockerfile, we use a multi-stage build to optimize the final Docker image. Here’s a breakdown of what each section does:

React: Scroll to Top Instantly After Router Transition

In a React application, it’s common to want to scroll to the top of the page instantly after a router transition, such as when navigating to a new page or route. This provides a smooth user experience and ensures that the user starts reading the new content from the top of the page. To achieve this, you can use JavaScript’s window.scrollTo() method with the behavior: 'instant' option. In this article, we’ll explore how to implement this behavior in a React application.

How to Rename Author on All Commits in Git

In Git, there may be situations where you need to update or correct author information on all commits, such as changing email addresses or fixing incorrect names. This guide will explain how to rename authors on all commits using the git-filter-repo tool.

Requirements

  1. git-filter-repo: You can install it from the official repository at https://github.com/newren/git-filter-repo.

Procedure

Step 1: Create a .mailmap File

Create a file named .mailmap in the root directory of your Git repository. This file will map the old author information to the new author information. The correct format for each entry is as follows:

GIT Commit Message Naming

Introduction

A well-structured commit message is crucial for maintaining a clean and readable project history. The Conventional Commits specification provides a standard format for commit messages, making it easier to generate changelogs, automate versioning, and improve collaboration. This document outlines the naming conventions and structure for Git commit messages.

Git Gitlab Flow

GitLab Flow is a set of best practices for using Git with GitLab, combining elements of Git Flow and GitHub Flow to support various workflows. It emphasizes the use of feature branches for development, with integration to GitLab’s CI/CD pipeline for continuous testing and deployment.

Production Branch

flowchart TB
a-->b-->c-->d-->e
f-->g
c--deployment-->g
g-->h
a[development]
b[development]
c[development]
d[development]
e[development]
f[production]
g[production]
h[production]

Environtment Branches

flowchart LR
a-->b-->c-->d
e-->f-->g-->h
i-->j-->k
a--deploy to\npre-prod-->e
c--deploy to\npre-prod-->g
e--production\ndeployment-->j
a[staging]
b[staging]
c[staging]
d[staging]
e[pre-prod]
f[pre-prod]
g[pre-prod]
h[pre-prod]
i[production]
j[production]
k[production]

Release Branches

flowchart LR
a-->b-->c-->d-->e
a-->f-->g
c-.-chery-pick-.->g
d-->i
a[main]
b[main]
c[main]
d[main]
e[main]
f[2.3-stable]
g[2.3-stable]
i[2.4-stable]
0%