Skip to content

Commit

Permalink
Rework project's structure
Browse files Browse the repository at this point in the history
  • Loading branch information
erickskrauch committed Feb 1, 2024
1 parent dac3ca9 commit 77e466c
Show file tree
Hide file tree
Showing 69 changed files with 130 additions and 161 deletions.
2 changes: 0 additions & 2 deletions .dockerignore

This file was deleted.

33 changes: 30 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,21 @@ jobs:
steps:
- uses: actions/checkout@v4

- id: version
name: Set up build version
run: |
if [[ $GITHUB_REF_TYPE == "tag" ]]; then
VERSION=${GITHUB_REF#refs/tags/}
else
BRANCH_NAME=${GITHUB_REF#refs/heads/}
SHORT_SHA=$(git rev-parse --short $GITHUB_SHA)
VERSION="${BRANCH_NAME}-${SHORT_SHA}"
fi
echo "### Version: $VERSION" >> $GITHUB_STEP_SUMMARY
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Setup Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
cache-dependency-path: go.sum
go-version-file: go.mod
Expand All @@ -45,9 +58,23 @@ jobs:
run: go test -v -race --tags redis -coverprofile=coverage.txt -covermode=atomic ./...

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4-beta
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

- name: Build
run: go build ./...
env:
CGO_ENABLED: 'false'
run: >
go build
-trimpath
-ldflags "-w -s -X github.com/elyby/chrly/internal/version.version=${{ steps.version.outputs.version }} -X github.com/elyby/chrly/internal/version.commit=${{ github.sha }}" \
-o ./chrly
./cmd/chrly/...
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: chrly-build-linux-amd64-${{ steps.version.outputs.version }}
path: ./chrly
compression-level: 0
16 changes: 11 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
.idea
docker-compose.yml
docker-compose.override.yml
vendor
.cover
# IDE files
.idea/
*.iml
.vscode

# Go mod vendoring
/vendor

# Local environment
/docker-compose.yml
/data
29 changes: 0 additions & 29 deletions Dockerfile

This file was deleted.

12 changes: 12 additions & 0 deletions build/package/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# syntax=docker/dockerfile:1
ARG BINARY

FROM scratch

EXPOSE 80

COPY --from=alpine:latest /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY ${BINARY} /usr/local/bin/chrly

ENTRYPOINT ["/usr/local/bin/chrly"]
CMD ["serve"]
16 changes: 16 additions & 0 deletions cmd/chrly/chrly.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

import (
"fmt"
"os"

. "github.com/elyby/chrly/internal/cmd"
)

func main() {
err := RootCmd.Execute()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
2 changes: 0 additions & 2 deletions data/redis/.gitignore

This file was deleted.

16 changes: 16 additions & 0 deletions deploy/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3'
services:
chrly:
image: elyby/chrly:latest
restart: always
ports:
- "80:80"
environment:
CHRLY_SECRET: replace_this_value_in_production
STORAGE_REDIS_HOST: redis

redis:
image: redis:latest
restart: always
volumes:
- ./data/redis:/data
14 changes: 0 additions & 14 deletions docker-compose.dev.yml

This file was deleted.

27 changes: 0 additions & 27 deletions docker-compose.prod.yml

This file was deleted.

12 changes: 0 additions & 12 deletions docker-entrypoint.sh

This file was deleted.

19 changes: 4 additions & 15 deletions cmd/root.go → internal/cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,24 @@
package cmd

import (
"fmt"
"log"
"os"
"strings"

. "github.com/defval/di"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/elyby/chrly/di"
"github.com/elyby/chrly/http"
"github.com/elyby/chrly/version"
"github.com/elyby/chrly/internal/di"
"github.com/elyby/chrly/internal/http"
"github.com/elyby/chrly/internal/version"
)

var RootCmd = &cobra.Command{
Use: "chrly",
Short: "Implementation of Minecraft skins system server",
Short: "Implementation of the Minecraft skins system server",
Version: version.Version(),
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if err := RootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}

func shouldGetContainer() *Container {
container, err := di.New()
if err != nil {
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion cmd/token.go → internal/cmd/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"

"github.com/elyby/chrly/http"
"github.com/elyby/chrly/internal/http"

"github.com/spf13/cobra"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go → internal/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/spf13/cobra"

"github.com/elyby/chrly/version"
"github.com/elyby/chrly/internal/version"
)

var versionCmd = &cobra.Command{
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion db/redis/redis.go → internal/db/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/mediocregopher/radix/v4"

"github.com/elyby/chrly/db"
"github.com/elyby/chrly/internal/db"
)

const usernameToProfileKey = "hash:username-to-profile"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
assert "github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"github.com/elyby/chrly/db"
"github.com/elyby/chrly/internal/db"
)

var redisAddr string
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions di/db.go → internal/di/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"github.com/defval/di"
"github.com/spf13/viper"

db2 "github.com/elyby/chrly/db"
"github.com/elyby/chrly/db/redis"
es "github.com/elyby/chrly/eventsubscribers"
db2 "github.com/elyby/chrly/internal/db"
"github.com/elyby/chrly/internal/db/redis"
es "github.com/elyby/chrly/internal/eventsubscribers"
"github.com/elyby/chrly/internal/mojang"
"github.com/elyby/chrly/internal/profiles"
"github.com/elyby/chrly/mojang"
)

// v4 had the idea that it would be possible to separate backends for storing skins and capes.
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions di/dispatcher.go → internal/di/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"github.com/defval/di"
"github.com/mono83/slf"

d "github.com/elyby/chrly/dispatcher"
"github.com/elyby/chrly/eventsubscribers"
"github.com/elyby/chrly/http"
d "github.com/elyby/chrly/internal/dispatcher"
"github.com/elyby/chrly/internal/eventsubscribers"
"github.com/elyby/chrly/internal/http"
)

var dispatcher = di.Options(
Expand Down
2 changes: 1 addition & 1 deletion di/handlers.go → internal/di/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/gorilla/mux"
"github.com/spf13/viper"

. "github.com/elyby/chrly/http"
. "github.com/elyby/chrly/internal/http"
)

var handlers = di.Options(
Expand Down
4 changes: 2 additions & 2 deletions di/logger.go → internal/di/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/mono83/slf/wd"
"github.com/spf13/viper"

"github.com/elyby/chrly/eventsubscribers"
"github.com/elyby/chrly/version"
"github.com/elyby/chrly/internal/eventsubscribers"
"github.com/elyby/chrly/internal/version"
)

var logger = di.Options(
Expand Down
2 changes: 1 addition & 1 deletion di/mojang_textures.go → internal/di/mojang_textures.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/defval/di"
"github.com/spf13/viper"

"github.com/elyby/chrly/internal/mojang"
"github.com/elyby/chrly/internal/profiles"
"github.com/elyby/chrly/mojang"
)

var mojangTextures = di.Options(
Expand Down
2 changes: 1 addition & 1 deletion di/profiles.go → internal/di/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package di
import (
"github.com/defval/di"

. "github.com/elyby/chrly/http"
. "github.com/elyby/chrly/internal/http"
"github.com/elyby/chrly/internal/profiles"
)

Expand Down
2 changes: 1 addition & 1 deletion di/server.go → internal/di/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/getsentry/raven-go"
"github.com/spf13/viper"

. "github.com/elyby/chrly/http"
. "github.com/elyby/chrly/internal/http"
)

var server = di.Options(
Expand Down
5 changes: 3 additions & 2 deletions di/signer.go → internal/di/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"encoding/base64"
"encoding/pem"
"errors"
"github.com/elyby/chrly/http"
. "github.com/elyby/chrly/signer"
"strings"

"github.com/elyby/chrly/internal/http"
. "github.com/elyby/chrly/internal/signer"

"github.com/defval/di"
"github.com/spf13/viper"
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/mono83/slf/params"
"github.com/stretchr/testify/mock"

"github.com/elyby/chrly/dispatcher"
"github.com/elyby/chrly/internal/dispatcher"
)

type LoggerMock struct {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/mono83/slf"

"github.com/elyby/chrly/dispatcher"
"github.com/elyby/chrly/internal/dispatcher"

"github.com/stretchr/testify/mock"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package eventsubscribers

import "github.com/elyby/chrly/dispatcher"
import "github.com/elyby/chrly/internal/dispatcher"

type Subscriber interface {
dispatcher.Subscriber
Expand Down
Loading

0 comments on commit 77e466c

Please sign in to comment.