Compare commits

..
3 Commits
Author SHA1 Message Date
Dustin Pianalto 13f80a6972 Add action to deploy to ECS after image is built
CI / build (push) Has been cancelled
2020-10-11 22:23:05 -08:00
Dustin Pianalto cadef92efb Add user to guild on user create 2020-10-09 23:43:56 -08:00
Dustin Pianalto a93139fcf2 Attempt to insert user into db before creating tag 2020-10-09 23:21:35 -08:00
6 changed files with 166 additions and 5 deletions
+18
View File
@@ -33,6 +33,7 @@ jobs:
uses: battila7/get-version-action@v2.0.0
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: goff
@@ -42,3 +43,20 @@ jobs:
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: "goff"
image: ${{ steps.build-image.outputs.image }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: "goff"
cluster: "discord-bots"
wait-for-service-stability: true
+6
View File
@@ -7,7 +7,9 @@ import (
"strings"
"github.com/dustinpianalto/disgoman"
"github.com/dustinpianalto/goff"
"github.com/dustinpianalto/goff/internal/postgres"
"github.com/dustinpianalto/goff/internal/services"
)
var AddTagCommand = &disgoman.Command{
@@ -55,6 +57,10 @@ func addTagCommandFunc(ctx disgoman.Context, input []string) {
}
return
}
err = services.UserService.CreateUser(&goff.User{ID: ctx.User.ID}, ctx.Guild.ID)
if err != nil {
log.Printf("Error creating user %s: %s", ctx.User.ID, err.Error())
}
queryString = `INSERT INTO tags (tag, content, creator, guild_id) VALUES ($1, $2, $3, $4);`
_, err := postgres.DB.Exec(queryString, tag, value, ctx.Message.Author.ID, ctx.Guild.ID)
if err != nil {
+1 -1
View File
@@ -25,7 +25,7 @@ func OnGuildMemberAdd(s *discordgo.Session, member *discordgo.GuildMemberAdd) {
IsStaff: false,
IsAdmin: false,
}
err := services.UserService.CreateUser(user)
err := services.UserService.CreateUser(user, member.GuildID)
if err != nil {
log.Println("Error adding user to database: ", err)
}
+6 -3
View File
@@ -36,10 +36,13 @@ func (s *UserService) User(id string) (*goff.User, error) {
return &u, nil
}
func (s *UserService) CreateUser(u *goff.User) error {
func (s *UserService) CreateUser(u *goff.User, gid string) error {
queryString := `INSERT INTO users (id, banned, logging, steam_id, is_active, is_staff, is_admin)
VALUES ($1, $2, $3, $4, $5, $6, $7)`
VALUES ($1, $2, $3, $4, $5, $6, $7) ON CONFLICT DO NOTHING`
_, err := s.DB.Exec(queryString, u.ID, u.Banned, u.Logging, u.SteamID, u.IsActive, u.IsStaff, u.IsAdmin)
if err == nil {
err = s.AddUserToGuild(u, &goff.Guild{ID: gid})
}
return err
}
@@ -59,7 +62,7 @@ func (s *UserService) MarkUserInactive(u *goff.User) error {
}
func (s *UserService) AddUserToGuild(u *goff.User, g *goff.Guild) error {
queryString := `INSERT INTO x_users_guilds (user_id, guild_id) VALUES ($1, $2)`
queryString := `INSERT INTO x_users_guilds (user_id, guild_id) VALUES ($1, $2) ON CONFLICT DO NOTHING`
_, err := s.DB.Exec(queryString, u.ID, g.ID)
return err
}
+134
View File
@@ -0,0 +1,134 @@
{
"ipcMode": null,
"executionRoleArn": "arn:aws:iam::005692590034:role/goff_ecs_rds+cw+ecr",
"containerDefinitions": [
{
"dnsSearchDomains": null,
"environmentFiles": null,
"logConfiguration": {
"logDriver": "awslogs",
"secretOptions": null,
"options": {
"awslogs-group": "/ecs/goff",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "ecs"
}
},
"entryPoint": null,
"portMappings": [],
"command": null,
"linuxParameters": null,
"cpu": 0,
"environment": [],
"resourceRequirements": null,
"ulimits": null,
"dnsServers": null,
"mountPoints": [],
"workingDirectory": null,
"secrets": [
{
"valueFrom": "goff_database_uri",
"name": "DATABASE_URL"
},
{
"valueFrom": "goff_discord_token",
"name": "DISCORDGO_TOKEN"
},
{
"valueFrom": "goff_email_password",
"name": "GOFF_EMAIL_PASSWORD"
},
{
"valueFrom": "goff_email_username",
"name": "GOFF_EMAIL_USERNAME"
}
],
"dockerSecurityOptions": null,
"memory": 512,
"memoryReservation": null,
"volumesFrom": [],
"stopTimeout": null,
"image": "005692590034.dkr.ecr.us-east-1.amazonaws.com/goff:latest",
"startTimeout": null,
"firelensConfiguration": null,
"dependsOn": null,
"disableNetworking": null,
"interactive": null,
"healthCheck": null,
"essential": true,
"links": null,
"hostname": null,
"extraHosts": null,
"pseudoTerminal": null,
"user": null,
"readonlyRootFilesystem": null,
"dockerLabels": null,
"systemControls": null,
"privileged": null,
"name": "goff"
}
],
"placementConstraints": [],
"memory": "512",
"taskRoleArn": "arn:aws:iam::005692590034:role/goff_ecs_rds+cw+ecr",
"compatibilities": [
"EC2"
],
"taskDefinitionArn": "arn:aws:ecs:us-east-1:005692590034:task-definition/goff:2",
"family": "goff",
"requiresAttributes": [
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.logging-driver.awslogs"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "ecs.capability.execution-role-awslogs"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.ecr-auth"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.19"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.task-iam-role"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "ecs.capability.execution-role-ecr-pull"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "ecs.capability.secrets.ssm.environment-variables"
}
],
"pidMode": null,
"requiresCompatibilities": [
"EC2"
],
"networkMode": null,
"cpu": "1024",
"revision": 2,
"status": "ACTIVE",
"inferenceAccelerators": null,
"proxyConfiguration": null,
"volumes": []
}
+1 -1
View File
@@ -13,7 +13,7 @@ type User struct {
type UserService interface {
User(id string) (*User, error)
CreateUser(u *User) error
CreateUser(u *User, gid string) error
DeleteUser(u *User) error
MarkUserInactive(u *User) error
AddUserToGuild(u *User, g *Guild) error