From 1fa8894ca3bb5887a955d66434522faee4fc34e1 Mon Sep 17 00:00:00 2001 From: Kesara Rathnayake Date: Mon, 8 May 2023 12:25:29 +1200 Subject: [PATCH 1/4] ci: Remove CircleCI integration --- .circleci/config.yml | 92 -------------------------------------- .circleci/ecs-preview.toml | 8 ---- infra | 1 - 3 files changed, 101 deletions(-) delete mode 100644 .circleci/config.yml delete mode 100644 .circleci/ecs-preview.toml delete mode 160000 infra diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index fe44d951..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,92 +0,0 @@ -version: 2.1 - -orbs: - buildkit: springload/buildkit@0.0.7 - -workflows: - build_test_and_push_image: - jobs: - - buildkit/builder: - cache_version: v4 - builds: - - buildkit/build: # call the build command multiple times to build multiple images - target: frontend # build this stage - tag: frontend # no tag no docker image - path: docker - - buildkit/build: # call the build command multiple times to build multiple images - target: aws-app # build this stage - tag: app # no tag no docker image - path: docker - - buildkit/build: # call the build command multiple times to build multiple images - target: app-test # build this stage - tag: app-test # no tag no docker image - path: docker - after-builds: - - run: - name: run backend tests - command: |- - set -eu - - docker run --name=database \ - -ePOSTGRES_DB=app \ - -ePOSTGRES_PASSWORD=password \ - -d postgres:11-alpine - docker run \ - -i --rm --name=app-test \ - -u root \ - --link=database \ - -eDATABASE_URL="postgres://postgres:password@database/app" \ - -eAPP_SECRET_KEY=xxxx \ - -eENVIRONMENT=test \ - app-test - - run: - name: tag, push and deploy images - command: |- - set -eu - if [ "${CIRCLE_BRANCH}" == "deploy/preview" ] || [ "${CIRCLE_BRANCH}" == "deploy/production" ]; then - ENVIRONMENT=`basename "${CIRCLE_BRANCH}"` - PROJECT=ietf - VERSION=$(git rev-parse --short HEAD) - wget -O ecs-tool.tar.gz https://github.com/springload/ecs-tool/releases/download/1.5.1/ecs-tool_1.5.1_linux_amd64.tar.gz && tar -C /usr/bin -xvf ecs-tool.tar.gz ecs-tool - apk add jq - export AWS_REGION=us-west-2 - export AWS_DEFAULT_REGION=us-west-2 - export REPOSITORY=$(ecs-tool ecr-endpoint) - eval $(ecs-tool ecr-login) - pids="" - for image in app; do - for tag in ${ENVIRONMENT}-${VERSION} ${ENVIRONMENT}-latest; do - docker tag ${image} ${REPOSITORY}/${PROJECT}-${image}:${tag} - docker push ${REPOSITORY}/${PROJECT}-${image}:${tag} & - pids="${pids} $!" - done - done - for p in $pids; do - wait $p - done - - # running the pre-deployment commands - ecs-tool -p "" --config ".circleci/ecs-${ENVIRONMENT}.toml" run --image_tag "${ENVIRONMENT}-${VERSION}" -- ./deploy.sh - # deploy new services in parallel - ecs-tool -p "" --config ".circleci/ecs-${ENVIRONMENT}.toml" deploy --image_tag "${ENVIRONMENT}-${VERSION}" - fi - - run: - name: test the website - command: |- - set -eu - - if [ "${CIRCLE_BRANCH}" == "deploy/preview" ] || [ "${CIRCLE_BRANCH}" == "deploy/production" ]; then - ENVIRONMENT=`basename "${CIRCLE_BRANCH}"` - # add more environments / endpoints as needed - case "${ENVIRONMENT}" in - production) - endpoint=https://www.ietf.org - ;; - preview) - endpoint=https://wwwdev.ietf.org - ;; - esac - - - docker run --rm -e BASIC_AUTH=$BASIC_AUTH frontend yarn test $endpoint - fi diff --git a/.circleci/ecs-preview.toml b/.circleci/ecs-preview.toml deleted file mode 100644 index 8111b2c4..00000000 --- a/.circleci/ecs-preview.toml +++ /dev/null @@ -1,8 +0,0 @@ -profile = "ietf" -cluster = "ietf-preview" -task_definition = "ietf-preview-app" -container_name = "app" -log_group = "ecs-tool" - -[deploy] -services = ["app"] diff --git a/infra b/infra deleted file mode 160000 index 08476d18..00000000 --- a/infra +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 08476d1896fc64938db90bd6a97b52c844671e81 From b72f51e097511855ece9b7838654ff2347651454 Mon Sep 17 00:00:00 2001 From: Kesara Rathnayake Date: Mon, 15 May 2023 17:04:14 +1200 Subject: [PATCH 2/4] ci: Refactor docker configuration --- docker-compose.yml | 5 ++++- docker/Dockerfile | 22 +--------------------- docker/db.Dockerfile | 12 +++++++++--- 3 files changed, 14 insertions(+), 25 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 4a95f68a..b1aba429 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,7 +27,10 @@ services: database: restart: on-failure - image: postgres:14.6-alpine + build: + context: . + dockerfile: docker/db.Dockerfile + target: db-local volumes: - "./docker/database:/docker-entrypoint-initdb.d/" environment: diff --git a/docker/Dockerfile b/docker/Dockerfile index 7b930ef8..ff330548 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -27,12 +27,6 @@ RUN yarn dist CMD ["yarn", "start"] -# --------------------------------------------------------------------- -# SSM-PARENT -# --------------------------------------------------------------------- -# Needed for hosting on AWS -FROM springload/ssm-parent:1.4.1 as ssm-parent - # --------------------------------------------------------------------- # BASE # --------------------------------------------------------------------- @@ -77,20 +71,6 @@ ENV PROJECT wagtail_website USER www -# --------------------------------------------------------------------- -# AWS - APP -# --------------------------------------------------------------------- -# AWS hosting stages -FROM base as aws-app - -# ssm-parent is needed for dynamic env-variable configuration on AWS. -# It just reads encrypted secrets from AWS SSM Parameter Store and exposes them -# as the environment variables to the process inside of the container -COPY --from=ssm-parent /usr/bin/ssm-parent /usr/bin/ssm-parent - -ENTRYPOINT ["/usr/bin/ssm-parent", "run", "-e", "-p", "/$PROJECT/common/", "-p", "/$PROJECT/$ENVIRONMENT/", "-n", "/$PROJECT/$ENVIRONMENT/ssm", "-r", "--"] -CMD ["/usr/local/bin/gunicorn", "--config", "/app/docker/gunicorn.py", "ietf.wsgi" ] - # --------------------------------------------------------------------- # APP # --------------------------------------------------------------------- @@ -149,4 +129,4 @@ COPY docker/supervisord-sandbox.conf /app/supervisord.conf RUN mkdir -p /app/media -CMD ["/usr/bin/supervisord", "-c", "/app/supervisord.conf"] \ No newline at end of file +CMD ["/usr/bin/supervisord", "-c", "/app/supervisord.conf"] diff --git a/docker/db.Dockerfile b/docker/db.Dockerfile index 2ccdf2aa..6befe073 100644 --- a/docker/db.Dockerfile +++ b/docker/db.Dockerfile @@ -1,7 +1,7 @@ # ===================== # --- Builder Stage --- # ===================== -FROM postgres:14.5 AS builder +FROM postgres:14.6 AS builder ENV POSTGRES_PASSWORD=password ENV POSTGRES_USER=postgres @@ -18,7 +18,7 @@ RUN ["/usr/local/bin/docker-entrypoint.sh", "postgres"] # =================== # --- Final Image --- # =================== -FROM postgres:14.5 +FROM postgres:14.6 LABEL maintainer="IETF Tools Team " COPY --from=builder /data $PGDATA @@ -26,4 +26,10 @@ COPY --from=builder /data $PGDATA ENV POSTGRES_PASSWORD=password ENV POSTGRES_USER=postgres ENV POSTGRES_DB=app -ENV POSTGRES_HOST_AUTH_METHOD=trust \ No newline at end of file +ENV POSTGRES_HOST_AUTH_METHOD=trust + +# ================================ +# --- Final Image with out data--- +# ================================ +FROM postgres:14.6 AS db-local +LABEL maintainer="IETF Tools Team " From edd62b08e1b45326020d7807fadeee67f7c698be Mon Sep 17 00:00:00 2001 From: Kesara Rathnayake Date: Thu, 22 Jun 2023 23:19:49 +1200 Subject: [PATCH 3/4] ci: Add GHA to run tests --- .github/workflows/ci-run-tests.yml | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/ci-run-tests.yml diff --git a/.github/workflows/ci-run-tests.yml b/.github/workflows/ci-run-tests.yml new file mode 100644 index 00000000..c16d4f43 --- /dev/null +++ b/.github/workflows/ci-run-tests.yml @@ -0,0 +1,40 @@ +name: Run tests +on: + push: + branches: + - main + pull_request: + branches: + - '*' + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Docker build app-test + uses: docker/build-push-action@v3 + with: + context: . + file: docker/Dockerfile + target: app-test + push: false + tags: app-test:latest + + - name: Docker build db-local + uses: docker/build-push-action@v3 + with: + context: . + file: docker/db.Dockerfile + target: db-local + push: false + tags: db-local:latest + + - name: Start database + run: docker run --name=database -e POSTGRES_DB=app -e POSTGRES_PASSWORD=password -d db-local:latest + + - name: Run tests + run: docker run -i --rm --name=app-test -u root --link=database -e DATABASE_URL="postgres://postgres:password@database/app" -e APP_SECRET_KEY=xxxx -e ENVIRONMENT=test app-test From 472734292bdc829b0e8bc4c204a79f64ef9a9361 Mon Sep 17 00:00:00 2001 From: Kesara Rathnayake Date: Tue, 27 Jun 2023 10:04:20 +1200 Subject: [PATCH 4/4] ci: Use PostgreSQL docker image directly --- .github/workflows/ci-run-tests.yml | 11 +---------- docker-compose.yml | 5 +---- docker/db.Dockerfile | 6 ------ 3 files changed, 2 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci-run-tests.yml b/.github/workflows/ci-run-tests.yml index c16d4f43..4b93c480 100644 --- a/.github/workflows/ci-run-tests.yml +++ b/.github/workflows/ci-run-tests.yml @@ -24,17 +24,8 @@ jobs: push: false tags: app-test:latest - - name: Docker build db-local - uses: docker/build-push-action@v3 - with: - context: . - file: docker/db.Dockerfile - target: db-local - push: false - tags: db-local:latest - - name: Start database - run: docker run --name=database -e POSTGRES_DB=app -e POSTGRES_PASSWORD=password -d db-local:latest + run: docker run --name=database -e POSTGRES_DB=app -e POSTGRES_PASSWORD=password -d postgres:14.6 - name: Run tests run: docker run -i --rm --name=app-test -u root --link=database -e DATABASE_URL="postgres://postgres:password@database/app" -e APP_SECRET_KEY=xxxx -e ENVIRONMENT=test app-test diff --git a/docker-compose.yml b/docker-compose.yml index b1aba429..350bca2d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,10 +27,7 @@ services: database: restart: on-failure - build: - context: . - dockerfile: docker/db.Dockerfile - target: db-local + image: postgres:14.6 volumes: - "./docker/database:/docker-entrypoint-initdb.d/" environment: diff --git a/docker/db.Dockerfile b/docker/db.Dockerfile index 6befe073..95c05ec3 100644 --- a/docker/db.Dockerfile +++ b/docker/db.Dockerfile @@ -27,9 +27,3 @@ ENV POSTGRES_PASSWORD=password ENV POSTGRES_USER=postgres ENV POSTGRES_DB=app ENV POSTGRES_HOST_AUTH_METHOD=trust - -# ================================ -# --- Final Image with out data--- -# ================================ -FROM postgres:14.6 AS db-local -LABEL maintainer="IETF Tools Team "