Skip to content

Commit 5b190d7

Browse files
Merge pull request #31 from Real-Dev-Squad/develop
Dev to Main Sync
2 parents 08a5d4c + aadcdf6 commit 5b190d7

37 files changed

+1420
-2
lines changed

.dockerignore

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Include any files or directories that you don't want to be copied to your
2+
# container here (e.g., local build artifacts, temporary files, etc.).
3+
#
4+
# For more help, visit the .dockerignore file reference guide at
5+
# https://docs.docker.com/go/build-context-dockerignore/
6+
7+
**/.DS_Store
8+
**/.classpath
9+
**/.dockerignore
10+
**/.env
11+
**/.git
12+
**/.gitignore
13+
**/.project
14+
**/.settings
15+
**/.toolstarget
16+
**/.vs
17+
**/.vscode
18+
**/*.*proj.user
19+
**/*.dbmdl
20+
**/*.jfm
21+
**/bin
22+
**/charts
23+
**/docker-compose*
24+
**/compose*
25+
**/Dockerfile*
26+
**/node_modules
27+
**/npm-debug.log
28+
**/obj
29+
**/tmp
30+
**/secrets.dev.yaml
31+
**/values.dev.yaml
32+
LICENSE
33+
README.md

.env.example

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
PORT = 8999
2+
DISCORD_PUBLIC_KEY = "<DISCORD_PUBLIC_KEY>"

.github/workflows/ci.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This workflow will build and test the Go code
2+
# This workflow will install Go dependencies, build the source code, and run tests.
3+
4+
name: Go CI Checks
5+
6+
on:
7+
pull_request:
8+
branches:
9+
- '**'
10+
push:
11+
branches:
12+
- 'main'
13+
- 'develop'
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
timeout-minutes: 5
19+
20+
strategy:
21+
matrix:
22+
go-version: [1.22.4]
23+
24+
steps:
25+
- name: Check out the code
26+
uses: actions/checkout@v4
27+
28+
- name: Set up Go ${{ matrix.go-version }}
29+
uses: actions/setup-go@v4
30+
with:
31+
go-version: ${{ matrix.go-version }}
32+
33+
- name: Install dependencies
34+
run: go mod download
35+
36+
- name: Build and test
37+
run: |
38+
go build ./...
39+
go test -v ./...

.github/workflows/deploy.yml

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Deploy to EC2
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
- main
8+
9+
jobs:
10+
build-and-push:
11+
runs-on: ubuntu-latest
12+
timeout-minutes: 10
13+
environment: ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }}
14+
15+
steps:
16+
- name: Checkout Repository
17+
uses: actions/checkout@v4
18+
19+
- name: Login to Docker Hub
20+
uses: docker/login-action@v3
21+
with:
22+
username: ${{ secrets.DOCKERHUB_USERNAME }}
23+
password: ${{ secrets.DOCKERHUB_TOKEN }}
24+
25+
- name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@v3
27+
28+
- name: Build and push
29+
uses: docker/build-push-action@v5
30+
with:
31+
context: .
32+
file: ./Dockerfile
33+
platforms: linux/arm64
34+
push: true
35+
tags: |
36+
${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ github.sha }}
37+
${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:latest
38+
cache-from: type=gha
39+
cache-to: type=gha,mode=max
40+
41+
- name: Deploy to EC2
42+
uses: appleboy/ssh-action@master
43+
with:
44+
host: ${{ secrets.AWS_EC2_HOST }}
45+
username: ${{ secrets.AWS_EC2_USERNAME }}
46+
key: ${{ secrets.AWS_EC2_SSH_PRIVATE_KEY }}
47+
script: |
48+
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:latest
49+
docker stop ${{ github.event.repository.name }}-${{vars.ENV}} || true
50+
docker rm ${{ github.event.repository.name }}-${{vars.ENV}} || true
51+
docker run -d -p ${{vars.PORT}}:${{vars.PORT}} \
52+
--name ${{ github.event.repository.name }}-${{vars.ENV}} \
53+
--network=${{vars.DOCKER_NETWORK}} \
54+
-e PORT=${{vars.PORT}} \
55+
-e DISCORD_PUBLIC_KEY=${{secrets.DISCORD_PUBLIC_KEY}} \
56+
-e BOT_TOKEN=${{secrets.BOT_TOKEN}} \
57+
-e GUILD_ID=${{secrets.GUILD_ID}} \
58+
${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.env
2+
.vscode
3+
coverage.html
4+
coverage.out
5+
build
6+
**/tmp

Dockerfile

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# syntax=docker/dockerfile:1
2+
3+
# Comments are provided throughout this file to help you get started.
4+
# If you need more help, visit the Dockerfile reference guide at
5+
# https://docs.docker.com/go/dockerfile-reference/
6+
7+
# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7
8+
9+
################################################################################
10+
# Create a stage for building the application.
11+
ARG GO_VERSION=1.22.4
12+
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION} AS build
13+
WORKDIR /src
14+
15+
# Download dependencies as a separate step to take advantage of Docker's caching.
16+
# Leverage a cache mount to /go/pkg/mod/ to speed up subsequent builds.
17+
# Leverage bind mounts to go.sum and go.mod to avoid having to copy them into
18+
# the container.
19+
RUN --mount=type=cache,target=/go/pkg/mod/ \
20+
--mount=type=bind,source=go.sum,target=go.sum \
21+
--mount=type=bind,source=go.mod,target=go.mod \
22+
go mod download -x
23+
24+
# This is the architecture you’re building for, which is passed in by the builder.
25+
# Placing it here allows the previous steps to be cached across architectures.
26+
ARG TARGETARCH
27+
28+
# Build the application.
29+
# Leverage a cache mount to /go/pkg/mod/ to speed up subsequent builds.
30+
# Leverage a bind mount to the current directory to avoid having to copy the
31+
# source code into the container.
32+
RUN --mount=type=cache,target=/go/pkg/mod/ \
33+
--mount=type=bind,target=. \
34+
CGO_ENABLED=0 GOARCH=$TARGETARCH go build -o /bin/server .
35+
36+
################################################################################
37+
# Create a new stage for running the application that contains the minimal
38+
# runtime dependencies for the application. This often uses a different base
39+
# image from the build stage where the necessary files are copied from the build
40+
# stage.
41+
#
42+
# The example below uses the alpine image as the foundation for running the app.
43+
# By specifying the "latest" tag, it will also use whatever happens to be the
44+
# most recent version of that image when you build your Dockerfile. If
45+
# reproducability is important, consider using a versioned tag
46+
# (e.g., alpine:3.17.2) or SHA (e.g., alpine@sha256:c41ab5c992deb4fe7e5da09f67a8804a46bd0592bfdf0b1847dde0e0889d2bff).
47+
FROM alpine:latest AS final
48+
49+
# Install any runtime dependencies that are needed to run your application.
50+
# Leverage a cache mount to /var/cache/apk/ to speed up subsequent builds.
51+
RUN --mount=type=cache,target=/var/cache/apk \
52+
apk --update add \
53+
ca-certificates \
54+
tzdata \
55+
&& \
56+
update-ca-certificates
57+
58+
# Create a non-privileged user that the app will run under.
59+
# See https://docs.docker.com/go/dockerfile-user-best-practices/
60+
ARG UID=10001
61+
RUN adduser \
62+
--disabled-password \
63+
--gecos "" \
64+
--home "/nonexistent" \
65+
--shell "/sbin/nologin" \
66+
--no-create-home \
67+
--uid "${UID}" \
68+
appuser
69+
USER appuser
70+
71+
# Copy the executable from the "build" stage.
72+
COPY --from=build /bin/server /bin/
73+
74+
# Expose the port that the application listens on.
75+
EXPOSE 8080
76+
77+
# What the container should run when it is started.
78+
ENTRYPOINT [ "/bin/server" ]

Makefile

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
air:
2+
@echo "Running the Go project using Air..."
3+
air
4+
5+
run:
6+
@echo "Running the Go project..."
7+
go run .
8+
9+
ngrok:
10+
@echo "Running the Go project using Ngrok..."
11+
ngrok http 8999
12+
13+
tidy:
14+
@echo "Running the Go project tidy..."
15+
@go mod tidy
16+
17+
download:
18+
@echo "Running the Go project tidy..."
19+
@go mod download
20+
21+
fmt:
22+
@echo "Running the Go project fmt..."
23+
@go fmt ./...
24+
25+
test:
26+
@echo "Running the Go project tests..."
27+
@go list ./... | grep -v "/config$$" | grep -v "/routes$$" | xargs go test -v -coverprofile=coverage.out
28+
29+
coverage:
30+
@echo "Running the Go project tests with coverage..."
31+
@go tool cover -func=coverage.out
32+
@go tool cover -html=coverage.out -o coverage.html
33+
34+
clean:
35+
@echo "Cleaning the Go project..."
36+
@rm -rf coverage
37+
@rm -rf coverage.out
38+
@rm -rf coverage.html
39+
40+
register:
41+
@echo "Registering commands..."
42+
@go run commands/main/register.go
43+
@echo "Registration complete."
44+
45+
test-cover:
46+
ifeq ($(FORCE),1)
47+
@echo "Force flag detected. Cleaning before tests..."
48+
@$(MAKE) clean
49+
endif
50+
@$(MAKE) test
51+
@$(MAKE) coverage
52+
@echo "Tests completed and coverage report generated."
53+
54+
55+

README.Docker.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
### Building and running your application
2+
3+
When you're ready, start your application by running:
4+
`docker compose up --build`.
5+
6+
Your application will be available at http://localhost:8080.
7+
8+
### Deploying your application to the cloud
9+
10+
First, build your image, e.g.: `docker build -t myapp .`.
11+
If your cloud uses a different CPU architecture than your development
12+
machine (e.g., you are on a Mac M1 and your cloud provider is amd64),
13+
you'll want to build the image for that platform, e.g.:
14+
`docker build --platform=linux/amd64 -t myapp .`.
15+
16+
Then, push it to your registry, e.g. `docker push myregistry.com/myapp`.
17+
18+
Consult Docker's [getting started](https://docs.docker.com/go/get-started-sharing/)
19+
docs for more detail on building and pushing.
20+
21+
### References
22+
* [Docker's Go guide](https://docs.docker.com/language/golang/)

0 commit comments

Comments
 (0)