From c72144b80fd382cda7199519d04e4e23b8a93643 Mon Sep 17 00:00:00 2001 From: Toby Bellwood Date: Tue, 6 Aug 2024 09:36:26 +1000 Subject: [PATCH 1/2] build: restructure docker compose for multistage --- docker-compose.yml | 21 +++++++++++++-------- lagoon/Dockerfile | 20 ++++++++++++++++++++ lagoon/cli.dockerfile | 10 ---------- lagoon/nginx.dockerfile | 9 --------- lagoon/php.dockerfile | 6 ------ 5 files changed, 33 insertions(+), 33 deletions(-) create mode 100644 lagoon/Dockerfile delete mode 100644 lagoon/cli.dockerfile delete mode 100644 lagoon/nginx.dockerfile delete mode 100644 lagoon/php.dockerfile diff --git a/docker-compose.yml b/docker-compose.yml index 734c529..906ad86 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,10 +28,12 @@ volumes: services: cli: # cli container, will be used for executing composer and any local commands (drush, drupal, etc.) + hostname: cli build: context: . - dockerfile: lagoon/cli.dockerfile - image: &cli-image ${COMPOSE_PROJECT_NAME:-drupal-base}-cli # this image will be reused as `CLI_IMAGE` in subsequent Docker builds + target: cli + dockerfile: lagoon/Dockerfile + image: drupal-base-cli:latest labels: # Lagoon Labels lagoon.type: cli-persistent @@ -46,11 +48,12 @@ services: << : *default-environment # loads the defined environment variables from the top nginx: + hostname: nginx build: context: . - dockerfile: lagoon/nginx.dockerfile - args: - CLI_IMAGE: *cli-image # Inject the name of the cli image + target: nginx + dockerfile: lagoon/Dockerfile + image: drupal-base-nginx:latest labels: lagoon.type: nginx-php-persistent lagoon.persistent: /app/web/sites/default/files/ # define where the persistent storage should be mounted too @@ -68,11 +71,12 @@ services: - default php: + hostname: php build: context: . - dockerfile: lagoon/php.dockerfile - args: - CLI_IMAGE: *cli-image + target: php + dockerfile: lagoon/Dockerfile + image: drupal-base-php:latest labels: lagoon.type: nginx-php-persistent lagoon.name: nginx # we want this service be part of the nginx pod in Lagoon @@ -100,3 +104,4 @@ services: networks: amazeeio-network: external: true + default: diff --git a/lagoon/Dockerfile b/lagoon/Dockerfile new file mode 100644 index 0000000..23256f8 --- /dev/null +++ b/lagoon/Dockerfile @@ -0,0 +1,20 @@ +FROM uselagoon/php-8.3-cli-drupal:latest AS cli + +COPY composer.* /app/ +COPY assets /app/assets +RUN --mount=type=cache,target=/home/.composer/cache composer install --no-dev +COPY . /app +RUN mkdir -p -v -m775 /app/web/sites/default/files + +# Define where the Drupal Root is located +ENV WEBROOT=web + +FROM uselagoon/nginx-drupal:latest AS nginx + +COPY --from=cli /app /app + +ENV WEBROOT=web + +FROM uselagoon/php-8.3-fpm:latest AS php + +COPY --from=cli /app /app diff --git a/lagoon/cli.dockerfile b/lagoon/cli.dockerfile deleted file mode 100644 index eba950a..0000000 --- a/lagoon/cli.dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM uselagoon/php-8.3-cli-drupal:latest - -COPY composer.* /app/ -COPY assets /app/assets -RUN composer install --no-dev -COPY . /app -RUN mkdir -p -v -m775 /app/web/sites/default/files - -# Define where the Drupal Root is located -ENV WEBROOT=web diff --git a/lagoon/nginx.dockerfile b/lagoon/nginx.dockerfile deleted file mode 100644 index ba5773a..0000000 --- a/lagoon/nginx.dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -ARG CLI_IMAGE=drupal-base-cli -FROM ${CLI_IMAGE} AS cli - -FROM uselagoon/nginx-drupal:latest - -COPY --from=cli /app /app - -# Define where the Drupal Root is located -ENV WEBROOT=web diff --git a/lagoon/php.dockerfile b/lagoon/php.dockerfile deleted file mode 100644 index 9137bfa..0000000 --- a/lagoon/php.dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -ARG CLI_IMAGE=drupal-base-cli -FROM ${CLI_IMAGE} AS cli - -FROM uselagoon/php-8.3-fpm:latest - -COPY --from=cli /app /app From 51307a8f9d2c606f0de60c789e4591583800aaf8 Mon Sep 17 00:00:00 2001 From: Toby Bellwood Date: Tue, 6 Aug 2024 09:36:52 +1000 Subject: [PATCH 2/2] build: introduce buildx action --- .github/workflows/build-base-images.yaml | 55 +++++++++++++----------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/.github/workflows/build-base-images.yaml b/.github/workflows/build-base-images.yaml index c271179..7ffb841 100644 --- a/.github/workflows/build-base-images.yaml +++ b/.github/workflows/build-base-images.yaml @@ -4,6 +4,7 @@ on: push: branches: - 'main' + - 'test_build' jobs: build: @@ -11,10 +12,10 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 # - name: Log in to Docker Hub # uses: docker/login-action@v2 @@ -22,31 +23,35 @@ jobs: # username: ${{ secrets.DOCKER_USERNAME }} # password: ${{ secrets.DOCKER_PASSWORD }} - # - name: Log in to GitHub Container Registry - # uses: docker/login-action@v2 - # with: - # registry: ghcr.io - # username: ${{ github.actor }} - # password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build drupal-base-cli image - run: docker build -t drupal-base-cli:latest -f ./lagoon/cli.dockerfile . - - - name: Build Docker images - run: docker compose -f docker-compose.yml build + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push remote + uses: docker/bake-action@v5 + with: + push: true + set: | + *.platform=linux/amd64,linux/arm64 + cli.tags=ghcr.io/${{ github.repository_owner }}/drupal-base-image/cli:latest + nginx.tags=ghcr.io/${{ github.repository_owner }}/drupal-base-image/nginx:latest + php.tags=ghcr.io/${{ github.repository_owner }}/drupal-base-image/php:latest - name: List images run: docker image ls - # - name: Tag Docker images - # run: | - # docker tag your-dockerhub-username/your-app:latest your-dockerhub-username/your-app:main - # docker tag your-dockerhub-username/your-app:latest ghcr.io/your-github-username/your-app:latest + - name: Build and push local + uses: docker/bake-action@v5 + with: + load: true + set: | + *.platform=linux/amd64 + cli.tags=drupal-base-cli:latest + nginx.tags=drupal-base-nginx:latest + php.tags=drupal-base-php:latest - # - name: Push Docker images to Docker Hub - # run: | - # docker push your-dockerhub-username/your-app:latest - # docker push your-dockerhub-username/your-app:main - - # - name: Push Docker images to GitHub Container Registry - # run: docker push ghcr.io/your-github-username/your-app:latest \ No newline at end of file + - name: List images + run: docker image ls