Migrate deployment to Gitea Actions and Portainer
Some checks failed
Build and Push Container / docker (push) Has been cancelled

This commit is contained in:
WayfinderAK 2026-03-22 11:43:02 -08:00
parent aea88c632e
commit cf6b7eae81
No known key found for this signature in database
27 changed files with 197 additions and 112 deletions

6
.dockerignore Normal file
View File

@ -0,0 +1,6 @@
.git
.github
.gitea
.env
.idea
goff

View File

@ -0,0 +1,64 @@
name: Build and Push Container
on:
push:
branches:
- master
- main
tags:
- v*
workflow_dispatch:
env:
REGISTRY: gitea.wayfinderak.com
IMAGE_NAME: wayfinderak/goff
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Gitea registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Prepare image tags
id: prep
shell: bash
run: |
short_sha="${GITHUB_SHA::7}"
tags="${REGISTRY}/${IMAGE_NAME}:sha-${short_sha}"
if [[ "${GITHUB_REF_TYPE}" == "branch" && ("${GITHUB_REF_NAME}" == "master" || "${GITHUB_REF_NAME}" == "main") ]]; then
tags+=$'\n'"${REGISTRY}/${IMAGE_NAME}:latest"
fi
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
version="${GITHUB_REF_NAME#v}"
tags+=$'\n'"${REGISTRY}/${IMAGE_NAME}:${version}"
fi
{
echo 'tags<<EOF'
echo "$tags"
echo 'EOF'
} >> "$GITHUB_OUTPUT"
- name: Build and push image
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.prep.outputs.tags }}

View File

@ -1,64 +1,64 @@
name: CI
name: Build and Push Container
# Controls when the action will run. Triggers the workflow on push to master or development
# with a tag like v1.0.0 or v1.0.0-dev
on:
push:
branches:
- master
- main
tags:
- v[0-9]+.[0-9]+.[0-9]+
- v[0-9]+.[0-9]+.[0-9]+-[a-zA-Z]+
- v*
workflow_dispatch:
env:
REGISTRY: gitea.wayfinderak.com
IMAGE_NAME: wayfinderak/goff
jobs:
build:
docker:
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v4
- name: Get Version
id: get_version
uses: battila7/get-version-action@v2.0.0
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: install buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Gitea registry
uses: docker/login-action@v3
with:
version: latest
registry: ${{ env.REGISTRY }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Docker Login
# You may pin to the exact commit or the version.
# uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
uses: docker/login-action@v1.10.0
with:
registry: ${{ secrets.DR_URL }}
# Username used to log against the Docker registry
username: ${{ secrets.DH_USERNAME }}
# Password or personal access token used to log against the Docker registry
password: ${{ secrets.DH_PASSWORD }}
# Log out from the Docker registry at the end of a job
logout: true
- name: Docker Build & Push
env:
IMAGE_TAG: ${{ steps.get_version.outputs.version-without-v }}
- name: Prepare image tags
id: prep
shell: bash
run: |
docker buildx build --push \
--tag ${{ secrets.DR_URL }}/goff:$IMAGE_TAG \
--platform linux/amd64,linux/arm/v7,linux/arm64 .
short_sha="${GITHUB_SHA::7}"
tags="${REGISTRY}/${IMAGE_NAME}:sha-${short_sha}"
- name: Update deployment file
run: TAG=${{ steps.get_version.outputs.version-without-v }} && sed -i 's|<IMAGE>|${{ secrets.DR_URL }}/goff:'${TAG}'|' $GITHUB_WORKSPACE/deployment.yml
if [[ "${GITHUB_REF_TYPE}" == "branch" && ("${GITHUB_REF_NAME}" == "master" || "${GITHUB_REF_NAME}" == "main") ]]; then
tags+=$'\n'"${REGISTRY}/${IMAGE_NAME}:latest"
fi
- uses: azure/k8s-set-context@v1
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
version="${GITHUB_REF_NAME#v}"
tags+=$'\n'"${REGISTRY}/${IMAGE_NAME}:${version}"
fi
{
echo 'tags<<EOF'
echo "$tags"
echo 'EOF'
} >> "$GITHUB_OUTPUT"
- name: Build and push image
uses: docker/build-push-action@v6
with:
method: kubeconfig
kubeconfig: ${{ secrets.KUBE_CONFIG }}
id: setcontext
- name: Deploy to Kubernetes
run: kubectl apply -f $GITHUB_WORKSPACE/deployment.yml
- name: Verify deployment
run: kubectl rollout status deployment/goff -n discord-bots
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.prep.outputs.tags }}

View File

@ -1,20 +1,18 @@
FROM golang:1.14-alpine as dev
FROM golang:1.22-alpine AS builder
WORKDIR /go/src/Goff
COPY ./go.mod .
COPY ./go.sum .
WORKDIR /src
RUN apk add --no-cache ca-certificates git tzdata
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go install github.com/dustinpianalto/goff/...
ARG TARGETARCH=amd64
RUN CGO_ENABLED=0 GOOS=linux GOARCH=$TARGETARCH go build -o /out/goff ./cmd/goff
CMD [ "go", "run", "cmd/goff/main.go"]
FROM alpine:3.20
RUN apk add --no-cache ca-certificates tzdata
from alpine
COPY --from=builder /out/goff /usr/local/bin/goff
WORKDIR /bin
COPY --from=dev /go/bin/goff ./goff
CMD [ "goff" ]
ENTRYPOINT ["/usr/local/bin/goff"]

0
cmd/goff/main Executable file → Normal file
View File

View File

@ -5,14 +5,14 @@ import (
"log"
"github.com/dustinpianalto/disgoman"
"github.com/dustinpianalto/goff/internal/exts"
"github.com/dustinpianalto/goff/internal/exts/guild_management"
"github.com/dustinpianalto/goff/internal/exts/logging"
"github.com/dustinpianalto/goff/internal/exts/tasks"
"github.com/dustinpianalto/goff/internal/exts/user_management"
"github.com/dustinpianalto/goff/internal/postgres"
"github.com/dustinpianalto/goff/internal/services"
"github.com/dustinpianalto/goff/pkg/email"
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts"
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/guild_management"
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/logging"
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/tasks"
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/user_management"
"gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
"gitea.wayfinderak.com/wayfinderak/goff/internal/services"
"gitea.wayfinderak.com/wayfinderak/goff/pkg/email"
//"github.com/MikeModder/anpan"
"os"

10
docker-compose.yml Normal file
View File

@ -0,0 +1,10 @@
services:
goff:
image: ${IMAGE:-gitea.wayfinderak.com/wayfinderak/goff:${IMAGE_TAG:-latest}}
container_name: goff
restart: unless-stopped
environment:
DATABASE_URL: ${DATABASE_URL}
DISCORDGO_TOKEN: ${DISCORDGO_TOKEN}
GOFF_EMAIL_USERNAME: ${GOFF_EMAIL_USERNAME}
GOFF_EMAIL_PASSWORD: ${GOFF_EMAIL_PASSWORD}

2
go.mod
View File

@ -1,4 +1,4 @@
module github.com/dustinpianalto/goff
module gitea.wayfinderak.com/wayfinderak/goff
go 1.14

View File

@ -6,8 +6,8 @@ import (
"strings"
"github.com/dustinpianalto/disgoman"
"github.com/dustinpianalto/goff/internal/postgres"
"github.com/dustinpianalto/goff/internal/services"
"gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
"gitea.wayfinderak.com/wayfinderak/goff/internal/services"
)
// Guild management commands

View File

@ -5,7 +5,7 @@ import (
"log"
"github.com/bwmarrin/discordgo"
"github.com/dustinpianalto/goff/internal/postgres"
"gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
)
func OnMessageUpdate(session *discordgo.Session, m *discordgo.MessageUpdate) {

View File

@ -2,15 +2,15 @@ package exts
import (
"github.com/dustinpianalto/disgoman"
"github.com/dustinpianalto/goff/internal/exts/fun"
"github.com/dustinpianalto/goff/internal/exts/guild_management"
"github.com/dustinpianalto/goff/internal/exts/roles"
"github.com/dustinpianalto/goff/internal/exts/tags"
"github.com/dustinpianalto/goff/internal/exts/tasks"
"github.com/dustinpianalto/goff/internal/exts/user_management"
"github.com/dustinpianalto/goff/internal/exts/utils"
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/fun"
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/guild_management"
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/roles"
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/tags"
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/tasks"
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/user_management"
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/utils"
"github.com/dustinpianalto/goff/internal/exts/p_interpreter"
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/p_interpreter"
)
func AddCommandHandlers(h *disgoman.CommandManager) {

View File

@ -4,7 +4,7 @@ import (
"fmt"
"github.com/bwmarrin/discordgo"
"github.com/dustinpianalto/goff/internal/postgres"
"gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
)
var LoggingChannel = make(chan *LogEvent, 10)

View File

@ -7,9 +7,9 @@ import (
"github.com/bwmarrin/discordgo"
"github.com/dustinpianalto/disgoman"
"github.com/dustinpianalto/goff"
"github.com/dustinpianalto/goff/internal/postgres"
"github.com/dustinpianalto/goff/internal/services"
"gitea.wayfinderak.com/wayfinderak/goff"
"gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
"gitea.wayfinderak.com/wayfinderak/goff/internal/services"
)
var MakeRoleSelfAssignableCommand = &disgoman.Command{

View File

@ -7,9 +7,9 @@ import (
"strings"
"github.com/dustinpianalto/disgoman"
"github.com/dustinpianalto/goff"
"github.com/dustinpianalto/goff/internal/postgres"
"github.com/dustinpianalto/goff/internal/services"
"gitea.wayfinderak.com/wayfinderak/goff"
"gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
"gitea.wayfinderak.com/wayfinderak/goff/internal/services"
)
var AddTagCommand = &disgoman.Command{

View File

@ -6,7 +6,7 @@ import (
"time"
"github.com/bwmarrin/discordgo"
"github.com/dustinpianalto/goff/internal/postgres"
"gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
)
type Task struct {

View File

@ -7,7 +7,7 @@ import (
"time"
"github.com/dustinpianalto/disgoman"
"github.com/dustinpianalto/goff/internal/postgres"
"gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
"github.com/olebedev/when"
"github.com/olebedev/when/rules/common"
"github.com/olebedev/when/rules/en"

View File

@ -4,8 +4,8 @@ import (
"log"
"github.com/bwmarrin/discordgo"
"github.com/dustinpianalto/goff"
"github.com/dustinpianalto/goff/internal/services"
"gitea.wayfinderak.com/wayfinderak/goff"
"gitea.wayfinderak.com/wayfinderak/goff/internal/services"
)
func OnGuildMemberAdd(s *discordgo.Session, member *discordgo.GuildMemberAdd) {

View File

@ -7,8 +7,8 @@ import (
"time"
"github.com/bwmarrin/discordgo"
"github.com/dustinpianalto/goff/internal/discord_utils"
"github.com/dustinpianalto/goff/internal/postgres"
"gitea.wayfinderak.com/wayfinderak/goff/internal/discord_utils"
"gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
)
func OnGuildMemberAddLogging(s *discordgo.Session, member *discordgo.GuildMemberAdd) {

View File

@ -8,7 +8,7 @@ import (
"github.com/bwmarrin/discordgo"
"github.com/dustinpianalto/disgoman"
"github.com/dustinpianalto/goff/internal/exts/logging"
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/logging"
)
var KickUserCommand = &disgoman.Command{

View File

@ -9,7 +9,7 @@ import (
"github.com/bwmarrin/discordgo"
"github.com/dustinpianalto/disgoman"
"github.com/dustinpianalto/goff/internal/discord_utils"
"gitea.wayfinderak.com/wayfinderak/goff/internal/discord_utils"
)
var PingCommand = &disgoman.Command{
@ -80,9 +80,9 @@ var GitCommand = &disgoman.Command{
func gitCommandFunc(ctx disgoman.Context, _ []string) {
embed := &discordgo.MessageEmbed{
Title: "Hi there, My code is on Github",
Title: "Hi there, my code is on Gitea",
Color: 0,
URL: "https://github.com/dustinpianalto/Goff",
URL: "https://gitea.wayfinderak.com/wayfinderak/goff",
}
_, err := ctx.Session.ChannelMessageSendEmbed(ctx.Channel.ID, embed)
if err != nil {

View File

@ -4,6 +4,7 @@ import (
"database/sql"
"fmt"
"log"
"time"
_ "github.com/lib/pq"
)
@ -16,12 +17,18 @@ func ConnectDatabase(dbConnString string) {
db, err := sql.Open("postgres", dbConnString)
if err != nil {
panic(fmt.Sprintf("Can't connect to the database. %v", err))
} else {
fmt.Println("Database Connected.")
}
db.SetMaxOpenConns(75) // The RDS instance has a max of 75 open connections
db.SetMaxIdleConns(5)
db.SetConnMaxLifetime(300)
db.SetMaxOpenConns(5)
db.SetMaxIdleConns(2)
db.SetConnMaxLifetime(30 * time.Minute)
db.SetConnMaxIdleTime(5 * time.Minute)
if err = db.Ping(); err != nil {
panic(fmt.Sprintf("Can't ping the database. %v", err))
}
fmt.Println("Database Connected.")
DB = db
}

View File

@ -4,7 +4,7 @@ import (
"database/sql"
"log"
"github.com/dustinpianalto/goff"
"gitea.wayfinderak.com/wayfinderak/goff"
)
type GuildService struct {

View File

@ -4,7 +4,7 @@ import (
"database/sql"
"log"
"github.com/dustinpianalto/goff"
"gitea.wayfinderak.com/wayfinderak/goff"
)
type RoleService struct {

View File

@ -3,7 +3,7 @@ package postgres
import (
"database/sql"
"github.com/dustinpianalto/goff"
"gitea.wayfinderak.com/wayfinderak/goff"
)
type UserService struct {

View File

@ -1,6 +1,6 @@
package services
import "github.com/dustinpianalto/goff"
import "gitea.wayfinderak.com/wayfinderak/goff"
var UserService goff.UserService
var GuildService goff.GuildService

View File

@ -9,7 +9,7 @@ import (
"time"
"github.com/bwmarrin/discordgo"
"github.com/dustinpianalto/goff/pkg/puzzles"
"gitea.wayfinderak.com/wayfinderak/goff/pkg/puzzles"
imap "github.com/emersion/go-imap"
"github.com/emersion/go-imap/client"
"github.com/emersion/go-message/mail"

View File

@ -8,8 +8,8 @@ import (
"time"
"github.com/bwmarrin/discordgo"
"github.com/dustinpianalto/goff"
"github.com/dustinpianalto/goff/internal/postgres"
"gitea.wayfinderak.com/wayfinderak/goff"
"gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
"github.com/emersion/go-message/mail"
)