Skip to content

Commit 5c694e9

Browse files
committed
feat: init repo
1 parent 8548dfe commit 5c694e9

21 files changed

+424
-2
lines changed

.dockerignore

Whitespace-only changes.

.env.example

Whitespace-only changes.

.github/CODEOWNERS

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners
2+
3+
## Global owners
4+
* @jd-apprentice

.github/pull_request_template.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Description
2+
3+
Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change.
4+
5+
Fixes # (issue)
6+
7+
## Type of change
8+
9+
Please delete options that are not relevant.
10+
11+
- [ ] Bug fix (non-breaking change which fixes an issue)
12+
- [ ] New feature (non-breaking change which adds functionality)
13+
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
14+
- [ ] This change requires a documentation update
15+
16+
# How Has This Been Tested?
17+
18+
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
19+
20+
- [ ] Test A
21+
- [ ] Test B
22+
23+
# Checklist:
24+
25+
- [ ] Do the application run in docker?
26+
- [ ] My code follows the style guidelines of this project
27+
- [ ] I have performed a self-review of my code
28+
- [ ] I have made corresponding changes to the documentation
29+

.github/workflows/release.yaml

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: Docker Publish
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
branches: [ "develop" ]
7+
paths:
8+
- 'src/**'
9+
- 'infra/docker/**'
10+
- 'infra/kubernetes/**'
11+
- 'infra/terraform/**'
12+
- '.github/workflows/release.yml'
13+
- 'tests/**'
14+
push:
15+
branches: [ "develop", "master" ]
16+
paths:
17+
- 'src/**'
18+
19+
env:
20+
BRANCH_NAME: ${{ github.ref_name }}
21+
APP_NAME: app_name
22+
APP_VERSION: latest
23+
APP_DEV_VERSION: unstable
24+
25+
jobs:
26+
27+
test:
28+
name: test
29+
runs-on: ubuntu-latest
30+
steps:
31+
32+
- name: Checkout
33+
uses: actions/checkout@v4
34+
35+
- name: Set up Go
36+
uses: actions/setup-go@v5
37+
with:
38+
go-version: 1.23.2
39+
40+
- name: Test
41+
run: go test -v ./tests
42+
43+
## Enable to deploy in develop branch
44+
# develop:
45+
# runs-on: ubuntu-latest
46+
# needs: test
47+
# if: ${{ github.ref_name != 'master' }}
48+
# steps:
49+
# - name: Checkout
50+
# uses: actions/checkout@v4
51+
52+
# - name: Login to Docker Hub
53+
# uses: docker/login-action@v2
54+
# with:
55+
# username: ${{ secrets.DOCKERHUB_USERNAME }}
56+
# password: ${{ secrets.DOCKERHUB_TOKEN }}
57+
58+
# - name: Set up Docker Buildx
59+
# uses: docker/setup-buildx-action@v3
60+
61+
# - name: Build and push - AMD64 - UNSTABLE
62+
# uses: docker/build-push-action@v6
63+
# with:
64+
# context: .
65+
# file: infra/docker/Dockerfile
66+
# push: true
67+
# tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.APP_NAME }}:X64_${{ env.APP_DEV_VERSION }}
68+
# platforms: linux/amd64
69+
70+
# - name: Build and push - ARM64 - UNSTABLE
71+
# uses: docker/build-push-action@v4
72+
# with:
73+
# context: .
74+
# file: infra/docker/ARM64.Dockerfile
75+
# push: true
76+
# tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.APP_NAME }}:ARM64_${{ env.APP_DEV_VERSION }}
77+
# platforms: linux/arm64
78+
79+
## Enable to deploy in master branch
80+
# production:
81+
# runs-on: ubuntu-latest
82+
# needs: test
83+
# if: ${{ github.ref_name == 'master' && github.event_name != 'pull_request' }}
84+
# steps:
85+
# - name: Checkout
86+
# uses: actions/checkout@v4
87+
88+
# - name: Login to Docker Hub
89+
# uses: docker/login-action@v2
90+
# with:
91+
# username: ${{ secrets.DOCKERHUB_USERNAME }}
92+
# password: ${{ secrets.DOCKERHUB_TOKEN }}
93+
94+
# - name: Set up Docker Buildx
95+
# uses: docker/setup-buildx-action@v3
96+
97+
# - name: Build and push - AMD64 - PROD
98+
# uses: docker/build-push-action@v6
99+
# with:
100+
# context: .
101+
# file: infra/docker/Dockerfile
102+
# push: true
103+
# tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.APP_NAME }}:X64_${{ env.APP_VERSION }}
104+
# platforms: linux/amd64
105+
106+
# - name: Build and push - ARM64 - PROD
107+
# uses: docker/build-push-action@v4
108+
# with:
109+
# context: .
110+
# file: infra/docker/ARM64.Dockerfile
111+
# push: true
112+
# tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.APP_NAME }}:ARM64_${{ env.APP_VERSION }}
113+
# platforms: linux/arm64

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ go.work.sum
2323

2424
# env file
2525
.env
26+
27+
# Binary
28+
bin/

.pre-commit-config.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
repos:
2+
- repo: https://github.com/dnephin/pre-commit-golang
3+
language: golang
4+
rev: v0.5.0
5+
hooks:
6+
- id: go-fmt
7+
- id: go-imports ## go install golang.org/x/tools/cmd/goimports@latest
8+
- id: no-go-testing
9+
- id: golangci-lint ## yay -S golangci-lint
10+
- id: go-unit-tests

CHANGELOG.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
## [0.0.1] 13-02-2025
11+
12+
### Added
13+
14+
- Initial release

CONTRIBUTE.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## 🤝 Contribute
2+
3+
- Fork the project
4+
- Create a new branch with your changes: `git checkout -b feature/my-feature`
5+
- For a fix or suggestion, create a new branch with your changes: `git checkout -b fix/my-fix`
6+
- Save your changes and create a commit message telling you what you did: `git commit -m "feature: My new feature"`
7+
- Submit your changes: `git push origin feature/my-feature`
8+
- Open a pull request with your branch
9+
- After the merge of your pull request is done, you can delete your branch
10+
- If you have any questions, please contact me at [email](mailto:[email protected])

Makefile

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
all: lint test imports build start
2+
3+
start:
4+
./bin/AppName
5+
6+
dev: path
7+
gowatch
8+
9+
fmt:
10+
@if [ -n "$$(go fmt ./src)" ]; then \
11+
echo "Code is not properly formatted"; \
12+
exit 1; \
13+
fi
14+
15+
pre-commit:
16+
pre-commit run --all
17+
18+
imports: path
19+
goimports -w ./src
20+
21+
lint: path
22+
golangci-lint run
23+
24+
lint-fix: path
25+
golangci-lint run --fix
26+
27+
clear:
28+
rm -rf ./bin
29+
30+
## https://github.com/golang-standards/project-layout/issues/113#issuecomment-1336514449
31+
build: clear fmt
32+
GOARCH=amd64 go build -o ./bin/AppName ./src/main.go
33+
34+
build-arm: clear fmt
35+
GOARCH=arm64 go build -o ./bin/AppName ./src/main.go
36+
37+
test:
38+
go test -v ./tests
39+
40+
path:
41+
export PATH=$$PATH:$$HOME/go/bin
42+
43+
### Kubernetes && Docker
44+
45+
## https://www.digitalocean.com/community/tutorials/how-to-use-minikube-for-local-kubernetes-development-and-testing
46+
k8s-up:
47+
minikube start
48+
49+
k8s-down:
50+
minikube stop
51+
52+
k8s-apply:
53+
kubectl apply -f ./infra/kubernetes
54+
55+
pods:
56+
kubectl get pods -A
57+
58+
compose-up:
59+
docker compose -f ./infra/docker/docker-compose.yml up -d --build
60+
61+
compose-down:
62+
docker compose -f ./infra/docker/docker-compose.yml down

README.md

+88-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,88 @@
1-
# jd-golang
2-
Template for my golang projects
1+
# 🐳 Golang template
2+
3+
[![All Contributors](https://img.shields.io/github/all-contributors/jd-apprentice/jd-golang?color=ee8449&style=flat-square)](#contributors)
4+
5+
Golang template that includes the following features:
6+
7+
## 📚 Features
8+
9+
- ✅ Pre-commit
10+
- ✅ CodeQL
11+
- ✅ Sentry
12+
- ✅ Docker
13+
- ✅ Terraform
14+
- ✅ Kubernetes
15+
- ✅ GitHub Actions
16+
- ✅ CHANGELOG
17+
- ✅ Makefile
18+
- ✅ CONTRIBUTE.md
19+
20+
## 🧰 Requirements
21+
22+
- Golang >= 1.23
23+
- Docker (optional)
24+
25+
## 💾 Instalation
26+
27+
To install the project, run the following command:
28+
29+
```shell
30+
git clone https://github.com/jd-apprentice/jd-golang.git
31+
cd jd-golang
32+
cp .env.example .env
33+
make dev
34+
```
35+
36+
Make sure to complete the `.env` file with the following information:
37+
38+
| Variable | Description |
39+
| --- | --- |
40+
| SENTRY_DSN | The Sentry DSN |
41+
42+
Change the default names with the following script:
43+
44+
```bash
45+
mak replace
46+
$ bash ./scripts/app_name.sh
47+
Enter the new name: sample
48+
Replacement completed. 🚀
49+
```
50+
51+
This will replace all `app_name` with `sample` in the project.
52+
53+
### Run with Golang
54+
55+
```bash
56+
make
57+
```
58+
59+
This will build the app with golang and execute the binary.
60+
61+
### Run with Docker 🐳
62+
63+
1. Build the image manually
64+
65+
Remember to replace `app_name` with the name of your app.
66+
67+
```bash
68+
docker build -f docker/base-x86_64.Dockerfile -t app_bin .
69+
docker build -f docker/app.Dockerfile -t app_name .
70+
make compose-up
71+
```
72+
73+
## 🤝 Contribute
74+
75+
- For more information, check the [CONTRIBUTE](./CONTRIBUTE.md) file
76+
77+
## ✨ Contributors
78+
79+
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
80+
81+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
82+
<!-- prettier-ignore-start -->
83+
<!-- markdownlint-disable -->
84+
<table>
85+
<tr>
86+
<td align="center"><a href="https://jonathan.com.ar/es"><img src="https://avatars.githubusercontent.com/u/68082746?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jonathan Dyallo</b></sub></a><br /><a href="https://github.com/jd-apprentice/waifuland-api/commits?author=jd-apprentice" title="Code">💻</a> <a href="https://github.com/jd-apprentice/waifuland-api/commits?author=jd-apprentice" title="Tests">⚠️</a> <a href="https://github.com/jd-apprentice/waifuland-api/commits?author=jd-apprentice" title="Documentation">📖</a> <a href="#maintenance-jd-apprentice" title="Maintenance">🚧</a></td>
87+
</tr>
88+
</table>

go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module jd-golang
2+
3+
go 1.23.0

infra/docker/app.Dockerfile

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM app_name:latest AS deps
2+
3+
FROM debian:stable
4+
5+
ARG UID=1000
6+
ARG GID=1000
7+
8+
RUN groupadd -g $GID app_user && \
9+
useradd -u $UID -g $GID -m -s /bin/bash app_user
10+
11+
RUN apt-get update && apt-get install -y \
12+
## Add your dependencies here
13+
apt-get clean && \
14+
rm -rf /var/lib/apt/lists/*
15+
16+
WORKDIR /base
17+
18+
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
19+
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
20+
21+
COPY --from=deps /app/app_name ./app_name
22+
23+
RUN chown -R app_user:app_user /base
24+
25+
USER app_user
26+
27+
ENTRYPOINT [ "/usr/local/bin/docker-entrypoint.sh" ]
28+
CMD [ "/base/app_name" ]

infra/docker/base-x64_86.Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM scratch
2+
3+
WORKDIR /app
4+
5+
COPY lib/app_name ./app_name

0 commit comments

Comments
 (0)