diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000..2d19fc7 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml new file mode 100644 index 0000000..04510c0 --- /dev/null +++ b/.github/workflows/docker.yaml @@ -0,0 +1,92 @@ +name: Build Docker Image + +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +env: + TAG_LOADBALANCER: mrcide/hintr-loadbalancer + TAG_LOADBALANCER_GHCR: mrc-ide/hintr-loadbalancer + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - id: extract_branch + name: Setup Environment + shell: bash + run: | + if [ "${{github.event_name}}" = "pull_request" ]; + then + LONG_SHA=${{ github.event.pull_request.head.sha }} + echo "CI_BRANCH=${{ github.head_ref }}" >> $GITHUB_OUTPUT + else + LONG_SHA=${GITHUB_SHA} + echo "CI_BRANCH=${{ github.ref_name }}" >> $GITHUB_OUTPUT + fi + echo "CI_SHA=${LONG_SHA:0:7}" >> $GITHUB_OUTPUT + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Login to GHCR (GitHub Packages) + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build dev loadbalancer container + uses: docker/build-push-action@v6 + if: github.event_name == 'pull_request' + with: + load: true + tags: | + ${{env.TAG_LOADBALANCER}}:${{steps.extract_branch.outputs.CI_BRANCH}} + ghcr.io/${{env.TAG_LOADBALANCER_GHCR}}:${{steps.extract_branch.outputs.CI_BRANCH}} + + - name: Build prod loadbalancer container + uses: docker/build-push-action@v6 + if: github.event_name != 'pull_request' + with: + load: true + tags: | + ${{env.TAG_LOADBALANCER}}:latest + ${{env.TAG_LOADBALANCER}}:${{steps.extract_branch.outputs.CI_BRANCH}} + ghcr.io/${{env.TAG_LOADBALANCER_GHCR}}:latest + ghcr.io/${{env.TAG_LOADBALANCER_GHCR}}:${{steps.extract_branch.outputs.CI_BRANCH}} + + - name: Test loadbalancer container + run: ./test + env: + TAG_BRANCH: ${{env.TAG_LOADBALANCER}}:${{steps.extract_branch.outputs.CI_BRANCH}} + + - name: Push dev loadbalancer container + uses: docker/build-push-action@v6 + if: github.event_name == 'pull_request' + with: + push: true + tags: | + ${{env.TAG_LOADBALANCER}}:${{steps.extract_branch.outputs.CI_BRANCH}} + ghcr.io/${{env.TAG_LOADBALANCER_GHCR}}:${{steps.extract_branch.outputs.CI_BRANCH}} + + - name: Push prod loadbalancer container + uses: docker/build-push-action@v6 + if: github.event_name != 'pull_request' + with: + push: true + tags: | + ${{env.TAG_LOADBALANCER}}:latest + ${{env.TAG_LOADBALANCER}}:${{steps.extract_branch.outputs.CI_BRANCH}} + ghcr.io/${{env.TAG_LOADBALANCER_GHCR}}:latest + ghcr.io/${{env.TAG_LOADBALANCER_GHCR}}:${{steps.extract_branch.outputs.CI_BRANCH}} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/Dockerfile b/Dockerfile index 534b1aa..c9bbce6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,9 @@ -FROM haproxytech/haproxy-debian:2.6 +FROM haproxytech/haproxy-debian:3.0 RUN apt-get update && apt-get install -y \ jq COPY bin /usr/local/bin COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg +COPY dataplaneapi.yaml /etc/haproxy/dataplaneapi.yaml \ No newline at end of file diff --git a/buildkite/pipeline.yml b/buildkite/pipeline.yml deleted file mode 100644 index 36de487..0000000 --- a/buildkite/pipeline.yml +++ /dev/null @@ -1,14 +0,0 @@ -steps: - - label: ":whale: Build" - command: build - - - wait - - - label: ":hammer: test" - command: test - - - wait - - - label: ":shipit: Push" - command: push - diff --git a/dataplaneapi.yaml b/dataplaneapi.yaml new file mode 100644 index 0000000..bd75465 --- /dev/null +++ b/dataplaneapi.yaml @@ -0,0 +1,12 @@ +dataplaneapi: + host: "0.0.0.0" + port: 5555 + userlist: + userlist: "haproxy-dataplaneapi" +haproxy: + reload: + reload_cmd: "kill -SIGUSR2 1" + restart_cmd: "kill -SIGUSR2 1" + reload_delay: 5 + config_file: "/usr/local/etc/haproxy/haproxy.cfg" + haproxy_bin: "/usr/sbin/haproxy" \ No newline at end of file diff --git a/haproxy.cfg b/haproxy.cfg index 50944b7..d76e389 100644 --- a/haproxy.cfg +++ b/haproxy.cfg @@ -6,7 +6,6 @@ global defaults mode http log global - option httplog log-format '{"time": "%tr", "server_queue_size": %sq, "backend_queue_size": %bq, "request": %{+Q}r}' timeout client 60s timeout connect 5s @@ -25,5 +24,5 @@ userlist haproxy-dataplaneapi user admin insecure-password mypassword program api - command /usr/bin/dataplaneapi --host 0.0.0.0 --port 5555 --haproxy-bin /usr/sbin/haproxy --config-file /usr/local/etc/haproxy/haproxy.cfg --reload-cmd "kill -SIGUSR2 1" --reload-delay 5 --userlist haproxy-dataplaneapi + command dataplaneapi no option start-on-reload diff --git a/test b/test index d168204..b08f4f3 100755 --- a/test +++ b/test @@ -1,10 +1,5 @@ #!/usr/bin/env bash set -ex -HERE=$(dirname $0) -. $HERE/common - -# In case we switch agents between steps or tag has been updated -docker pull $TAG_SHA NAME_NETWORK=hintr_network NAME_LOADBALANCER=hintr_loadbalancer @@ -34,7 +29,7 @@ docker run --rm -d --network=$NAME_NETWORK \ docker run --rm -d --network=$NAME_NETWORK \ -p 8888:8888 \ --name $NAME_LOADBALANCER \ - $TAG_SHA + "$TAG_BRANCH" ## Data API is running sleep 2