Skip to content

Commit

Permalink
feat(docker): Initial version of docker build
Browse files Browse the repository at this point in the history
- Builds Magento data artifacts based on metadata
- Stores artifacts for future docker containers creation
- Caches build process for efficiency
  • Loading branch information
IvanChepurnyi committed Jan 3, 2025
1 parent 734345e commit ac1f5f1
Show file tree
Hide file tree
Showing 29 changed files with 173,323 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/tests export-ignore
/.github export-ignore
27 changes: 27 additions & 0 deletions .github/actions/build-image/Dockerfile-mariadb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
ARG SOURCE_VERSION

FROM wardenenv/mariadb:${SOURCE_VERSION} as mariadb-setup

ENV MYSQL_DATABASE magento
ENV MYSQL_PASSWORD magento
ENV MYSQL_ROOT_PASSWORD magento
ENV MYSQL_USER magento
ENV MYSQL_INIT_ONLY 1

# Prevent executing server on build run
RUN ["sed", "-i", "s/exec \\\"$@\\\"/ /", "/usr/local/bin/docker-entrypoint.sh"]
RUN /usr/bin/install -m 0775 -o mysql -g root -d /setup/
COPY dump.sql /docker-entrypoint-initdb.d/

RUN ["docker-entrypoint.sh", "mariadbd"]

RUN mv /var/lib/mysql /setup/db

FROM wardenenv/mariadb:${SOURCE_VERSION}

ENV MYSQL_DATABASE magento
ENV MYSQL_PASSWORD magento
ENV MYSQL_ROOT_PASSWORD magento
ENV MYSQL_USER magento

COPY --from=mariadb-setup /setup/db /var/lib/mysql
32 changes: 32 additions & 0 deletions .github/actions/build-image/Dockerfile-mysql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
ARG SOURCE_VERSION

FROM wardenenv/mysql:${SOURCE_VERSION} as mysql-setup

ENV MYSQL_DATABASE magento
ENV MYSQL_PASSWORD magento
ENV MYSQL_ROOT_PASSWORD magento
ENV MYSQL_USER magento
ENV MYSQL_INIT_ONLY 1

USER root
# Prevent executing server on build run
RUN ["sed", "-i", "s/exec \\\"$@\\\"/ /", "/usr/local/bin/docker-entrypoint.sh"]
RUN /usr/bin/install -m 0775 -o mysql -g root -d /setup/
USER mysql

COPY dump.sql /docker-entrypoint-initdb.d/

RUN ["docker-entrypoint.sh", "mysqld"]

USER root
RUN mv /var/lib/mysql /setup/db
USER mysql

FROM wardenenv/mysql:${SOURCE_VERSION}

ENV MYSQL_DATABASE magento
ENV MYSQL_PASSWORD magento
ENV MYSQL_ROOT_PASSWORD magento
ENV MYSQL_USER magento

COPY --from=mysql-setup /setup/db /var/lib/mysql
6 changes: 6 additions & 0 deletions .github/actions/build-image/Dockerfile-opensearch
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ARG SOURCE_VERSION

FROM wardenenv/opensearch:${SOURCE_VERSION}

RUN rm -rf /usr/share/opensearch/data
COPY search/ /usr/share/opensearch/data
97 changes: 97 additions & 0 deletions .github/actions/build-image/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Build Docker Image Based on Provided Data Artifact
description: Generates single database version per Magento release for both MariaDB and MySQL
author: Ivan Chepurnyi <[email protected]>
inputs:
artifact:
required: true
description: Name of artifact to build image from
containerType:
description: Container Type
required: true
registry:
description: Container registry
default: ghcr.io
username:
description: Container registry username
password:
description: Container registry password
imageName:
description: Image name
required: true
imageTags:
description: Image Tags
required: true
push:
default: 'false'
description: Push Images to repository
version:
required: true
description: Base version of image to use
runs:
using: composite
steps:
- name: Create artifact directory
run: mkdir -p artifact/
shell: bash

- name: Install cosign
if: inputs.push != 'false'
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0
with:
cosign-release: 'v2.2.4'

- name: Download artifact
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
with:
github-token: ${{ inputs.password }}
path: artifact/
name: ${{ inputs.artifact }}

- name: Unpack search directory
run: |
cd artifact
tar xzvf search.tgz
shell: bash

- name: Set up QEMU
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5

- name: Log into registry ${{ inputs.registry }}
if: inputs.push != 'false'
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
with:
registry: ${{ inputs.registry }}
username: ${{ inputs.username }}
password: ${{ inputs.password }}

- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96
with:
images: ${{ inputs.registry }}/${{ inputs.imageName }}
tags: ${{ inputs.imageTags }}

- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355
with:
context: artifact/
file: ${{ github.action_path }}/Dockerfile-${{ inputs.containerType }}
push: ${{ inputs.push != 'false' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: SOURCE_VERSION=${{ inputs.version }}

- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
TAGS: ${{ steps.meta.outputs.tags }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
shell: bash
47 changes: 47 additions & 0 deletions .github/actions/build-magento/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Build Magento Data Artifact
description: Generates single database version per Magento release for both MariaDB and MySQL
author: Ivan Chepurnyi <[email protected]>
inputs:
mariadb:
description: Version of MariaDB container
required: true
opensearch:
description: Version of Opensearch container
required: true
php:
description: Version of PHP container
required: true
version:
description: Version of Magento install
required: true
kind:
required: false
description: Type of install (default, sampledata)
default: default
artifact:
required: true
description: Name of the artifact directory
composerRepository:
required: false
default: https://mirror.mage-os.org/
description: Composer repository for installation
composerAuth:
required: false
description: COMPOSER_AUTH value
default: "{}"
containers:
required: false
description: JSON with containers that are going to be generated
default: "[]"
stability:
required: false
description: Preferred stability for composer packages
default: "stable"
outputs:
containers:
description: "Container configuration JSON"
artifact:
description: "Name of the artifact"
runs:
using: node20
main: dist/index.js
Loading

0 comments on commit ac1f5f1

Please sign in to comment.