Skip to content

Commit

Permalink
Feat : Added docker file and readme (#21)
Browse files Browse the repository at this point in the history
* Feat : Added docker file and readme

* Readme : Updated readme

* Feat : Updated docker compose file

* Chore : Changed default port
  • Loading branch information
joyguptaa authored Nov 16, 2024
1 parent 9628b18 commit 19a65b1
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
PORT = <PORT>
PORT = 8999
MODE = <MODE>
DISCORD_PUBLIC_KEY = "<DISCORD_PUBLIC_KEY>"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.env
.vscode
coverage.html
coverage.out
coverage.out
build
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM golang:1.22.4-alpine AS builder
WORKDIR /
COPY go.mod go.sum ./
RUN go mod download
COPY . .
# Register commands & make sure all env vars are present
RUN go run commands/main/register.go
RUN go build -o server .
FROM alpine:latest
COPY --from=builder /server /server
COPY --from=builder .env .env
EXPOSE 8080
ENTRYPOINT ["/server"]
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ run:

ngrok:
@echo "Running the Go project using Ngrok..."
ngrok http 8080
ngrok http 8999

tidy:
@echo "Running the Go project tidy..."
@go mod tidy

download:
@echo "Running the Go project tidy..."
@go mod download

fmt:
@echo "Running the Go project fmt..."
@go fmt ./...
Expand Down
140 changes: 138 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,138 @@
# website-template
A template to create all public facing sites
# Discord Service Setup and Running Instructions

This document provides instructions on how to set up and run the Go project using the provided `Makefile` commands.

## Requirements

- Go 1.18+
- Make
- Air (for `make air`)
- Ngrok (for `make ngrok`)

Ensure you have these dependencies installed before running the commands.

## Prerequisites

Before running the project, ensure that you have the following installed:

- **Go 1.18+**: The Go programming language (required to run and build the project).
- **Air**: A live-reloading tool for Go that will automatically restart the project on file changes.
- **Ngrok**: A tool to create a public URL for your local development server (useful for testing webhooks or exposing services to the internet).
- **Make**: A build automation tool used to manage tasks defined in the `Makefile`.

### Installation

1. **Install Go**
If you don't have Go installed, follow the official guide to install it:[Go Installation Guide](https://go.dev/doc/install).
2. **Install Make**
To install Make, follow the installations steps from here based on your OS:
[Make Installation Guide.](https://www.geeksforgeeks.org/how-to-install-make-on-ubuntu/)
3. **Install Ngrok**
To install Ngrok, follow the installation steps here:
[Ngrok Installation Guide](https://download.ngrok.com/).
4. **Install Air**
To install Air, follow the installation steps here:
[Air Installation Guide](https://github.com/air-verse/air)


## Running the Project Using Go

1. **Install Packages**

```bash
go mod download
```

2. **Verify Packages**
If it's your first time running the project, ensure all dependencies are set up:

```bash
go mod tidy
```

3. **Running the Project**

```bash
go run .
```

4. **Running the Project Using Air**

```bash
air
```


## Running the Project Using Make

You can run the project using the `Makefile`, which provides several commands for various tasks. Below are the steps to run the project:

1. **Install Packages**

```bash
make download
```

2. **Verify Packages**
If it's your first time running the project, ensure all dependencies are set up:

```bash
make tidy
```

3. **Running the Project**

```bash
make run
```

4. **Running the Project Using Air**

```bash
make air
```

## Run the Project Using Docker

You can run the project using the `Docker`, using the following steps

1. **Compose the Image**

```bash
docker-compose up --build
```

You can also run the command above in _detach_ mode by specifying `-d` flag in the end

2. **Remove the Image**
If you are done with running the docker image and want to remove the image, run the ocmmand below

```bash
docker-compose down
```

## Other Commands Usage

1. **To run tests**:

```bash
make test #or go list ./... | grep -v "/config$$" | grep -v "/routes$$" | xargs go test -v
```

2. **To generate a coverage report**:

```bash
make coverage #or go list ./... | grep -v "/config$$" | grep -v "/routes$$" | xargs go test -v -coverprofile=coverage.out
```

3. **To automatically re-run the application on changes**:

```bash
make air #or air
```

4. **To clean up the generated files**:

```bash
make clean #or rm -rf coverage coverage.out coverage.html
```
19 changes: 19 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '3.8'

services:
go-app:
build:
context: .
dockerfile: Dockerfile
ports:
- '8999:8080'
env_file:
- .env
volumes:
- .:/app
networks:
- app-network

networks:
app-network:
driver: bridge

0 comments on commit 19a65b1

Please sign in to comment.