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: on:
push: push:
tags: branches:
- v[0-9]+.[0-9]+.[0-9]+ - master
- v[0-9]+.[0-9]+.[0-9]+-[a-zA-Z]+ - main
tags:
- v*
workflow_dispatch:
env:
REGISTRY: gitea.wayfinderak.com
IMAGE_NAME: wayfinderak/goff
jobs: jobs:
build: docker:
runs-on: ubuntu-latest runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps: steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - name: Checkout
- uses: actions/checkout@v2 uses: actions/checkout@v4
- name: Get Version
id: get_version
uses: battila7/get-version-action@v2.0.0
- name: install buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v1
with:
version: latest
- name: Docker Login - name: Set up QEMU
# You may pin to the exact commit or the version. uses: docker/setup-qemu-action@v3
# 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 - name: Set up Docker Buildx
env: uses: docker/setup-buildx-action@v3
IMAGE_TAG: ${{ steps.get_version.outputs.version-without-v }}
- 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: | run: |
docker buildx build --push \ short_sha="${GITHUB_SHA::7}"
--tag ${{ secrets.DR_URL }}/goff:$IMAGE_TAG \ tags="${REGISTRY}/${IMAGE_NAME}:sha-${short_sha}"
--platform linux/amd64,linux/arm/v7,linux/arm64 .
- name: Update deployment file if [[ "${GITHUB_REF_TYPE}" == "branch" && ("${GITHUB_REF_NAME}" == "master" || "${GITHUB_REF_NAME}" == "main") ]]; then
run: TAG=${{ steps.get_version.outputs.version-without-v }} && sed -i 's|<IMAGE>|${{ secrets.DR_URL }}/goff:'${TAG}'|' $GITHUB_WORKSPACE/deployment.yml 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: with:
method: kubeconfig context: .
kubeconfig: ${{ secrets.KUBE_CONFIG }} push: true
id: setcontext platforms: linux/amd64,linux/arm64
tags: ${{ steps.prep.outputs.tags }}
- name: Deploy to Kubernetes
run: kubectl apply -f $GITHUB_WORKSPACE/deployment.yml
- name: Verify deployment
run: kubectl rollout status deployment/goff -n discord-bots

View File

@ -1,20 +1,18 @@
FROM golang:1.14-alpine as dev FROM golang:1.22-alpine AS builder
WORKDIR /go/src/Goff WORKDIR /src
COPY ./go.mod . RUN apk add --no-cache ca-certificates git tzdata
COPY ./go.sum .
COPY go.mod go.sum ./
RUN go mod download RUN go mod download
COPY . . 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 ENTRYPOINT ["/usr/local/bin/goff"]
COPY --from=dev /go/bin/goff ./goff
CMD [ "goff" ]

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

View File

@ -5,14 +5,14 @@ import (
"log" "log"
"github.com/dustinpianalto/disgoman" "github.com/dustinpianalto/disgoman"
"github.com/dustinpianalto/goff/internal/exts" "gitea.wayfinderak.com/wayfinderak/goff/internal/exts"
"github.com/dustinpianalto/goff/internal/exts/guild_management" "gitea.wayfinderak.com/wayfinderak/goff/internal/exts/guild_management"
"github.com/dustinpianalto/goff/internal/exts/logging" "gitea.wayfinderak.com/wayfinderak/goff/internal/exts/logging"
"github.com/dustinpianalto/goff/internal/exts/tasks" "gitea.wayfinderak.com/wayfinderak/goff/internal/exts/tasks"
"github.com/dustinpianalto/goff/internal/exts/user_management" "gitea.wayfinderak.com/wayfinderak/goff/internal/exts/user_management"
"github.com/dustinpianalto/goff/internal/postgres" "gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
"github.com/dustinpianalto/goff/internal/services" "gitea.wayfinderak.com/wayfinderak/goff/internal/services"
"github.com/dustinpianalto/goff/pkg/email" "gitea.wayfinderak.com/wayfinderak/goff/pkg/email"
//"github.com/MikeModder/anpan" //"github.com/MikeModder/anpan"
"os" "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 go 1.14

View File

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

View File

@ -5,7 +5,7 @@ import (
"log" "log"
"github.com/bwmarrin/discordgo" "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) { func OnMessageUpdate(session *discordgo.Session, m *discordgo.MessageUpdate) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,7 +7,7 @@ import (
"time" "time"
"github.com/dustinpianalto/disgoman" "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"
"github.com/olebedev/when/rules/common" "github.com/olebedev/when/rules/common"
"github.com/olebedev/when/rules/en" "github.com/olebedev/when/rules/en"

View File

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

View File

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

View File

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

View File

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

View File

@ -4,6 +4,7 @@ import (
"database/sql" "database/sql"
"fmt" "fmt"
"log" "log"
"time"
_ "github.com/lib/pq" _ "github.com/lib/pq"
) )
@ -16,12 +17,18 @@ func ConnectDatabase(dbConnString string) {
db, err := sql.Open("postgres", dbConnString) db, err := sql.Open("postgres", dbConnString)
if err != nil { if err != nil {
panic(fmt.Sprintf("Can't connect to the database. %v", err)) 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.SetMaxOpenConns(5)
db.SetConnMaxLifetime(300) 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 DB = db
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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