Skip to content

Instantly share code, notes, and snippets.

@jaysonsantos
Last active December 28, 2019 20:07
Show Gist options
  • Save jaysonsantos/df42c2f4d406a48ab18007b10de98b9d to your computer and use it in GitHub Desktop.
Save jaysonsantos/df42c2f4d406a48ab18007b10de98b9d to your computer and use it in GitHub Desktop.
killbill api with fargate/ecs/kubernetes systems
FROM killbill/killbill:0.20.0
ADD kpm.yml /var/lib/killbill/kpm.yml
# Patch to respect X-Fowarded-Proto and others when running with ELB
ADD server.xml.patch ./
RUN patch -p1 < server.xml.patch
# Script that setup traps to respect docker stop commands and stop catalina
ADD fargate-killbill.sh ./
#!/usr/bin/env bash
set -ex
stop_catalina() {
echo "Signal received, shutting down"
$CATALINA_HOME/bin/catalina.sh stop 30
}
main() {
trap "stop_catalina" SIGINT SIGTERM SIGHUP
export KILLBILL_QUEUE_CREATOR_NAME=$(hostname -i)
$KPM_INSTALL_CMD
$START_TOMCAT_CMD
touch $CATALINA_BASE/logs/killbill.out
tail -F $CATALINA_BASE/logs/killbill.out &
# At this point we don't need debug output
set +x
# Traps only work with builtin commands
while true; do
sleep 1s
done
}
main
--- a/conf/server.xml 2018-07-19 23:00:52.000000000 +0000
+++ b/conf/server.xml 2019-07-08 15:09:25.371411195 +0000
@@ -34,6 +34,7 @@
pattern="%h %l %u %t &quot;%m %U&quot; %s %b %D" />
<Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />
+ <Valve className="org.apache.catalina.valves.RemoteIpValve" remoteIpHeader="x-forwarded-for" proxiesHeader="x-forwarded-by" protocolHeader="x-forwarded-proto" />
</Host>
</Engine>
</Service>
@simcen
Copy link

simcen commented Nov 3, 2019

Hello. I stumbled accross your gist and assuming you're running killbill on ECS, which is also my goal. How are you calling fargate-killbill.sh? Would you mind to share your ECS task definition? Thank you!

@jaysonsantos
Copy link
Author

@simcen hey there, here it goes for the api:

{
  "ipcMode": null,
  "executionRoleArn": "arn:aws:iam::xxxx:role/ecsTaskExecutionRole",
  "containerDefinitions": [
    {
      "dnsSearchDomains": null,
      "logConfiguration": {
        "logDriver": "awslogs",
        "secretOptions": null,
        "options": {
          "awslogs-group": "/ecs/staging/killbill",
          "awslogs-region": "eu-central-1",
          "awslogs-stream-prefix": "api"
        }
      },
      "entryPoint": null,
      "portMappings": [
        {
          "hostPort": 8080,
          "protocol": "tcp",
          "containerPort": 8080
        }
      ],
      "command": [
        "./fargate-killbill.sh"
      ],
      "linuxParameters": null,
      "cpu": 1024,
      "environment": [
        {
          "name": "NEW_RELIC_ENVIRONMENT",
          "value": "staging"
        }
      ],
      "resourceRequirements": null,
      "ulimits": null,
      "dnsServers": null,
      "mountPoints": [],
      "workingDirectory": null,
      "secrets": [
        {
          "valueFrom": "/staging/killbill/killbill_dao_url",
          "name": "KILLBILL_DAO_URL"
        },
        {
          "valueFrom": "/staging/killbill/killbill_dao_user",
          "name": "KILLBILL_DAO_USER"
        },
        {
          "valueFrom": "/staging/killbill/killbill_dao_password",
          "name": "KILLBILL_DAO_PASSWORD"
        },
        {
          "valueFrom": "/staging/killbill/kaui_killbill_url",
          "name": "KILLBILL_SERVER_BASE_URL"
        }
      ],
      "dockerSecurityOptions": null,
      "memory": 4096,
      "memoryReservation": null,
      "volumesFrom": [],
      "stopTimeout": null,
      "image": "xxxx.dkr.ecr.eu-central-1.amazonaws.com/killbill-integration:master",
      "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": "api"
    }
  ],
  "placementConstraints": [],
  "memory": "4096",
  "taskRoleArn": null,
  "compatibilities": [
    "EC2",
    "FARGATE"
  ],
  "taskDefinitionArn": "arn:aws:ecs:eu-central-1:xxxx:task-definition/killbill-api-staging:16",
  "family": "killbill-api-staging",
  "requiresAttributes": [
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "ecs.capability.execution-role-ecr-pull"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "com.amazonaws.ecs.capability.docker-remote-api.1.18"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "ecs.capability.task-eni"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "com.amazonaws.ecs.capability.ecr-auth"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "ecs.capability.execution-role-awslogs"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "com.amazonaws.ecs.capability.logging-driver.awslogs"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "ecs.capability.secrets.ssm.environment-variables"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "com.amazonaws.ecs.capability.docker-remote-api.1.19"
    }
  ],
  "pidMode": null,
  "requiresCompatibilities": [
    "FARGATE"
  ],
  "networkMode": "awsvpc",
  "cpu": "1024",
  "revision": 16,
  "status": "ACTIVE",
  "inferenceAccelerators": null,
  "proxyConfiguration": null,
  "volumes": []
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment