Skip to content

Commit

Permalink
CDPT 1528 - install wp offload media pro (#545)
Browse files Browse the repository at this point in the history
* Add AS3CF_PRO

* Fix unused var

* Server name not generated locally

* New command: make composer-update

* Include composer auth

* Use correct var names
  • Loading branch information
wilson1000 authored Apr 23, 2024
1 parent 9bd26d3 commit 61690e7
Show file tree
Hide file tree
Showing 16 changed files with 320 additions and 152 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ COMPOSER_PASS=some_password
# used so composer can access repos
COMPOSER_TOKEN=some_token

AS3CF_PRO_LICENCE=license
AS3CF_PRO_USER=username
AS3CF_PRO_PASS=password

# used for wp-cron
NGINX_SERVICE_PORT=http://nginx:8080

Expand Down
71 changes: 56 additions & 15 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ https://intranet.justice.gov.uk/

## Summary

> Nb. `README.md` is located in `.github/`, the preferred location for a clean repository.
> Nb. `README.md` is located in `.github/`

## Installation for development
Expand All @@ -28,7 +28,7 @@ The application uses Docker. This repository provides two separate local test en
1. Docker Compose
2. Kubernetes

Where `docker compose` provides a pre-production environment to develop features and apply upgrades, Kubernetes allows
Where `docker compose` provides a pre-production environment to apply upgrades and develop features, Kubernetes allows
us to test and debug our deployments to the Cloud Platform.

### Setup
Expand All @@ -45,7 +45,11 @@ Change directories:
cd intranet
```

Next, depending on the environment you would like to launch, do one of the following.
Next, depending on the environment you would like to launch, choose one of the following:

- [Docker Compose](#1-docker-compose)
- [Kubernetes](#2-kubernetes)


### 1. Docker Compose

Expand All @@ -58,7 +62,7 @@ This environment has been set up to develop and improve the application.

The following make command will get you up and running.

It creates the environment, starts all services and opens a command prompt on the container that houses our PHP code,
It creates the environment and starts all services,
the service is called `php-fpm`:

```bash
Expand All @@ -69,23 +73,17 @@ During the `make` process, the Dory proxy will attempt to install. You will be g

### Services

You will have five services running with different access points. They are:
You will have ten services running in total, all with different access points. They are:

**Nginx**<br>
http://intranet.docker/

**PHP-FPM**<br>
**PHP-FPM**

```bash
make bash
```

On first use, the application will need initializing with the following command.

```bash
composer install
```

**Node**<br>
This service watches and compiles our assets, no need to access. The output of this service is available on STDOUT.

Expand All @@ -102,10 +100,53 @@ Internally accessed by PHP-FPM on port 3306

**PHPMyAdmin**<br>
http://intranet.docker:9191/ <br>
Login details located in `docker-compose.yml`
Login information can be found in [.env](https://github.com/ministryofjustice/intranet/blob/develop/.env.example#L16)


**Opensearch**

We use this

**Opensearch Dashboard**

Dashboards that allow us to query indexed data.

**Minio**

Minio acts just like an AWS S3 bucket.

**CDN**

This service acts like a distributed CloudFront service allowing us to imitate a CDN.

**CRON**

In production we have a scalable cron container. It's only job right now is to make a head request to `wp-cron.php`
There is no need to access this container. However, with every running container you can reach the OS.

```bash
docker compose exec -it wp-cron ash
```

---

> There is no need to install application software on your computer.<br>
> All required software is built within the services and all services are ephemeral.
> All required software is built within the services - all services are ephemeral.
**Composer**

We match the process that occurs in production CI locally to ensure we test against the same criteria.
As such, during development it will be necessary to rebuild directories when updating composer.

**After making changes to `composer.json`**...

```bash
make composer-update
```

This will fire off a set of checks, ensuring composer updates and all static assets are distributed correctly.
For more information, review [Dockerfile](https://github.com/ministryofjustice/intranet/blob/develop/Dockerfile#L125)
and [local assets files](https://github.com/ministryofjustice/intranet/blob/develop/bin/local-composer-assets.sh#L10).

#### Volumes

Expand All @@ -130,7 +171,7 @@ Once the above requirements have been met, we are able to launch our application
command:

```bash
make local-kube
make kube
```

The following will take place:
Expand Down
26 changes: 23 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,35 @@ jobs:

- name: "Build & Push to ECR"
run: |
docker image build -t $REGISTRY/$REPOSITORY:fpm-$IMAGE_TAG --target build-fpm --build-arg COMPOSER_USER="$COMPOSER_USER" --build-arg COMPOSER_PASS="$COMPOSER_PASS" .
docker image build -t $REGISTRY/$REPOSITORY:nginx-$IMAGE_TAG --target build-nginx --build-arg COMPOSER_USER="$COMPOSER_USER" --build-arg COMPOSER_PASS="$COMPOSER_PASS" .
docker image build -t $REGISTRY/$REPOSITORY:cron-$IMAGE_TAG --target build-cron .
# ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░
docker image build -t $REGISTRY/$REPOSITORY:fpm-$IMAGE_TAG \
--build-arg COMPOSER_USER="$COMPOSER_USER" --build-arg COMPOSER_PASS="$COMPOSER_PASS" \
--build-arg AS3CF_PRO_USER="$AS3CF_PRO_USER" --build-arg AS3CF_PRO_PASS="$AS3CF_PRO_PASS" \
--target build-fpm .
docker image build -t $REGISTRY/$REPOSITORY:nginx-$IMAGE_TAG \
--build-arg COMPOSER_USER="$COMPOSER_USER" --build-arg COMPOSER_PASS="$COMPOSER_PASS" \
--build-arg AS3CF_PRO_USER="$AS3CF_PRO_USER" --build-arg AS3CF_PRO_PASS="$AS3CF_PRO_PASS" \
--target build-nginx .
docker image build -t $REGISTRY/$REPOSITORY:cron-$IMAGE_TAG \
--target build-cron .
# ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░
docker push $REGISTRY/$REPOSITORY:fpm-$IMAGE_TAG
docker push $REGISTRY/$REPOSITORY:nginx-$IMAGE_TAG
docker push $REGISTRY/$REPOSITORY:cron-$IMAGE_TAG
# ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░
env:
REGISTRY: ${{ steps.ecr-login.outputs.registry }}
REPOSITORY: ${{ vars.ECR_REPOSITORY }}
IMAGE_TAG: ${{ github.sha }}
COMPOSER_USER: ${{ secrets.COMPOSER_USER }}
COMPOSER_PASS: ${{ secrets.COMPOSER_PASS }}
AS3CF_PRO_USER: ${{ secrets.AS3CF_PRO_USER }}
AS3CF_PRO_PASS: ${{ secrets.AS3CF_PRO_PASS }}
2 changes: 2 additions & 0 deletions .github/workflows/php-composer-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ jobs:
env:
COMPOSER_USER: ${{ secrets.COMPOSER_USER }}
COMPOSER_PASS: ${{ secrets.COMPOSER_PASS }}
AS3CF_PRO_USER: ${{ secrets.AS3CF_PRO_USER }}
AS3CF_PRO_PASS: ${{ secrets.AS3CF_PRO_PASS }}

- name: "Run tests"
run: make test
14 changes: 12 additions & 2 deletions .github/workflows/snyk-security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,21 @@ jobs:
# Build the docker images for testing
- name: Container monitor ~ build FPM & Nginx Docker images
run: |
docker image build --build-arg COMPOSER_USER="$COMPOSER_USER" --build-arg COMPOSER_PASS="$COMPOSER_PASS" -t intranet-fpm:snyk --target build-fpm .
docker image build --build-arg COMPOSER_USER="$COMPOSER_USER" --build-arg COMPOSER_PASS="$COMPOSER_PASS" -t intranet-nginx:snyk --target build-nginx .
docker image build \
--build-arg COMPOSER_USER="$COMPOSER_USER" --build-arg COMPOSER_PASS="$COMPOSER_PASS" \
--build-arg AS3CF_PRO_USER="$AS3CF_PRO_USER" --build-arg AS3CF_PRO_PASS="$AS3CF_PRO_PASS" \
-t intranet-fpm:snyk --target build-fpm .
docker image build \
--build-arg COMPOSER_USER="$COMPOSER_USER" --build-arg COMPOSER_PASS="$COMPOSER_PASS" \
--build-arg AS3CF_PRO_USER="$AS3CF_PRO_USER" --build-arg AS3CF_PRO_PASS="$AS3CF_PRO_PASS" \
-t intranet-nginx:snyk --target build-nginx .
env:
COMPOSER_USER: ${{ secrets.COMPOSER_USER }}
COMPOSER_PASS: ${{ secrets.COMPOSER_PASS }}
AS3CF_PRO_USER: ${{ secrets.AS3CF_PRO_USER }}
AS3CF_PRO_PASS: ${{ secrets.AS3CF_PRO_PASS }}

# Runs Snyk Container (Container and SCA) analysis.
- name: Container monitor ~ analyse
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public/app/mu-plugins/*/
public/app/upgrade
public/app/languages/*
public/app/uploads/*
vendor
vendor-assets
vendor*
.dory.yml
!deploy/config/local/.dory.yml
auth.json
Expand Down
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ USER 101

FROM base-fpm AS fpm-dev

RUN apk add zip

WORKDIR /var/www/html

COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
Expand Down Expand Up @@ -111,6 +113,8 @@ FROM base-fpm AS build-fpm-composer

ARG COMPOSER_USER
ARG COMPOSER_PASS
ARG AS3CF_PRO_USER
ARG AS3CF_PRO_PASS

COPY --from=composer:2 /usr/bin/composer /usr/bin/composer

Expand Down
Loading

0 comments on commit 61690e7

Please sign in to comment.