diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..1dddaae --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,62 @@ +name: CI + +# 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: + tags: + - v[0-9]+.[0-9]+.[0-9]+ + - v[0-9]+.[0-9]+.[0-9]+-[a-zA-Z]+ + +jobs: + build: + 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: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + - name: Get Version + id: get_version + 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: geeksbot + IMAGE_TAG: ${{ steps.get_version.outputs.version-without-v }} + run: | + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . + 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: "geeksbot" + 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: "geeksbot" + cluster: "discord-bots" + wait-for-service-stability: true diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e58e5a2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +.idea diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2838ae9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM golang:1.14-alpine as dev + +WORKDIR /go/src/Geeksbot +COPY ./go.mod . +COPY ./go.sum . + +RUN go mod download + +COPY . . +RUN go install github.com/dustinpianalto/geeksbot/... + +CMD [ "go", "run", "cmd/geeksbot/main.go"] + +from alpine + +WORKDIR /bin + +COPY --from=dev /go/bin/geeksbot ./geeksbot + +CMD [ "geeksbot" ] diff --git a/cmd/geeksbot/main.go b/cmd/geeksbot/main.go new file mode 100644 index 0000000..e69de29 diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..5e51d7a --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/dustinpianalto/geeksbot + +go 1.14 diff --git a/task-definition.json b/task-definition.json new file mode 100644 index 0000000..f4ad8f0 --- /dev/null +++ b/task-definition.json @@ -0,0 +1,126 @@ +{ + "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/geeksbot", + "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": "geeksbot_database_uri", + "name": "DATABASE_URL" + }, + { + "valueFrom": "geeksbot_discord_token", + "name": "DISCORDGO_TOKEN" + } + ], + "dockerSecurityOptions": null, + "memory": 512, + "memoryReservation": null, + "volumesFrom": [], + "stopTimeout": null, + "image": "005692590034.dkr.ecr.us-east-1.amazonaws.com/geeksbot: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": "geeksbot" + } + ], + "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/geeksbot:1", + "family": "geeksbot", + "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": [] +}