diff --git a/.github/workflows/locust-distributed.yaml b/.github/workflows/locust-distributed.yaml new file mode 100644 index 0000000..7ade55d --- /dev/null +++ b/.github/workflows/locust-distributed.yaml @@ -0,0 +1,57 @@ +name: locust-distributed + +on: + push: + branches: + - master + - feature/* + paths: + - 'locust-distributed/**' + - .github/workflows/locust-distributed.yaml + + +env: + IMAGE_NAME: locust + +jobs: + build-and-publish-latest: + runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v2 + + # - name: Build image + # run: docker build --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" locust/ + + # - name: Log into registry + # run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + + # - name: Push image + # run: | + # IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME + # IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + # docker tag $IMAGE_NAME $IMAGE_ID:latest + # docker push $IMAGE_ID:latest + + steps: + - name: Check out the repo + uses: actions/checkout@v3 + + - name: Inject slug/short variables + uses: rlespinasse/github-slug-action@v3.x + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Repository + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Container Image to GitHub Container Repository + uses: docker/build-push-action@v6 + with: + context: ./locust + push: true + tags: ghcr.io/base2services/locust-distributed:snapshot_${{env.GITHUB_SHA_SHORT}} \ No newline at end of file diff --git a/.github/workflows/locust.yaml b/.github/workflows/locust.yaml index bc1d30b..d955b48 100644 --- a/.github/workflows/locust.yaml +++ b/.github/workflows/locust.yaml @@ -2,13 +2,9 @@ name: locust on: push: - branches: - - master - - feature/* + branches: [ master ] paths: - 'locust/**' - - .github/workflows/locust.yaml - env: IMAGE_NAME: locust @@ -16,42 +12,20 @@ env: jobs: build-and-publish-latest: runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v2 + if: github.ref == 'refs/heads/master' # Running this job only for master branch + + steps: + - uses: actions/checkout@v2 - # - name: Build image - # run: docker build --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" locust/ + - name: Build image + run: docker build --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" locust/ - # - name: Log into registry - # run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + - name: Log into registry + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin - # - name: Push image - # run: | - # IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME - # IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') - # docker tag $IMAGE_NAME $IMAGE_ID:latest - # docker push $IMAGE_ID:latest - - steps: - - name: Check out the repo - uses: actions/checkout@v3 - - - name: Inject slug/short variables - uses: rlespinasse/github-slug-action@v3.x - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to GitHub Container Repository - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and push Container Image to GitHub Container Repository - uses: docker/build-push-action@v6 - with: - context: ./locust - push: true - tags: ghcr.io/base2services/locust:snapshot_${{env.GITHUB_REF_SLUG}} \ No newline at end of file + - name: Push image + run: | + IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + docker tag $IMAGE_NAME $IMAGE_ID:latest + docker push $IMAGE_ID:latest diff --git a/locust-distributed/Dockerfile b/locust-distributed/Dockerfile new file mode 100644 index 0000000..f3e6519 --- /dev/null +++ b/locust-distributed/Dockerfile @@ -0,0 +1,14 @@ +FROM locustio/locust:2.23.1 + +LABEL org.opencontainers.image.source=https://github.com/base2Services/build-containers + +USER root +RUN pip install awscli faker + +WORKDIR /locust + +ENTRYPOINT [ "/entrypoint" ] + +CMD [ "locust" ] + +COPY docker-entrypoint.sh /entrypoint \ No newline at end of file diff --git a/locust-distributed/docker-entrypoint.sh b/locust-distributed/docker-entrypoint.sh new file mode 100755 index 0000000..8413051 --- /dev/null +++ b/locust-distributed/docker-entrypoint.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +set -ex + +aws s3 cp s3://${LOCUST_S3_PATH} /locust/ --recursive --region ${AWS_REGION} + +LOCUST_MODE=${LOCUST_MODE:-standalone} +LOCUST_MASTER_BIND_PORT=${LOCUST_MASTER_BIND_PORT:-5557} +LOCUST_FILE=${LOCUST_FILE:-locustfile.py} +LOCUST_LOG_LEVEL=${LOCUST_LOG_LEVEL:-INFO} + +LOCUST_OPTS="-f ${LOCUST_FILE}" + +if [ -z ${HOST_URL+x} ] ; then + echo "No value set for (HOST_URL), falling back to host value in the locust class" +else + echo "(HOST_URL) set to ${HOST_URL}" + LOCUST_OPTS="--host=${HOST_URL} $LOCUST_OPTS" +fi + +case `echo ${LOCUST_MODE} | tr 'a-z' 'A-Z'` in +"MASTER") + LOCUST_OPTS="--master --master-bind-port=${LOCUST_MASTER_BIND_PORT} $LOCUST_OPTS" + ;; + +"SLAVE") + LOCUST_OPTS="--worker --master-host=${LOCUST_MASTER} --master-port=${LOCUST_MASTER_BIND_PORT} $LOCUST_OPTS" + echo "${LOCUST_OPTS}" + if [ -z ${LOCUST_MASTER+x} ] ; then + echo "You need to set LOCUST_MASTER." + exit 1 + fi + ;; +esac + +exec "$@" ${LOCUST_OPTS} \ No newline at end of file diff --git a/locust/docker-entrypoint.sh b/locust/docker-entrypoint.sh index c00011e..56792cf 100755 --- a/locust/docker-entrypoint.sh +++ b/locust/docker-entrypoint.sh @@ -1,35 +1,17 @@ #!/bin/sh -set -ex +set -e -aws s3 cp s3://${LOCUST_S3_PATH} /locust/ --recursive --region ${AWS_REGION} - -LOCUST_MODE=${LOCUST_MODE:-standalone} -LOCUST_MASTER_BIND_PORT=${LOCUST_MASTER_BIND_PORT:-5557} -LOCUST_FILE=${LOCUST_FILE:-locustfile.py} -LOCUST_LOG_LEVEL=${LOCUST_LOG_LEVEL:-INFO} - -LOCUST_OPTS="-f ${LOCUST_FILE}" - -if [ -z ${HOST_URL+x} ] ; then - echo "No value set for (HOST_URL), falling back to host value in the locust class" -else - echo "(HOST_URL) set to ${HOST_URL}" - LOCUST_OPTS="--host=${HOST_URL} $LOCUST_OPTS" +if [ "x" != "${LOCUST_S3_PATH}x" ] ; then + aws s3 cp s3://${LOCUST_S3_PATH}/${LOCUST_LOCUSTFILE} . --region ${AWS_REGION} + chmod +x ${LOCUST_LOCUSTFILE} fi -case `echo ${LOCUST_MODE} | tr 'a-z' 'A-Z'` in -"MASTER") - LOCUST_OPTS="--master --master-bind-port=${LOCUST_MASTER_BIND_PORT} $LOCUST_OPTS" - ;; - -"SLAVE") - LOCUST_OPTS="--worker --master-host=${LOCUST_MASTER} --master-port=${LOCUST_MASTER_BIND_PORT} $LOCUST_OPTS" - if [ -z ${LOCUST_MASTER+x} ] ; then - echo "You need to set LOCUST_MASTER." +if [ ${1} = "locust" ] ; then + echo "Starting locust......." + if [ -z ${LOCUST_HOST+x} ] ; then + echo "You need to set the URL of the host to be tested (LOCUST_HOST)." exit 1 fi - ;; -esac - -exec "$@" ${LOCUST_OPTS} \ No newline at end of file +fi +exec "$@" \ No newline at end of file