diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 91fb34f..488d13b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -51,39 +51,41 @@ build-debian: - build/*.deb # Build the Alpine Docker image -ncc-docker-build: +ncc-docker-build-alpine: image: docker:latest - stage: build-docker + stage: build-docker-alpine services: - docker:dind before_script: - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY script: - | - if [[ ! -z "$CI_COMMIT_TAG" ]]; then + if [[ "$CI_COMMIT_BRANCH" == "master" ]]; then + DOCKER_TAG="latest-alpine" + elif [[ ! -z "$CI_COMMIT_TAG" ]]; then DOCKER_TAG="$CI_COMMIT_TAG-alpine" else DOCKER_TAG="$CI_COMMIT_REF_SLUG-alpine" fi - - docker build -f Dockerfile -t $CI_REGISTRY_IMAGE:$DOCKER_TAG . + - docker build -f Dockerfile.alpine -t $CI_REGISTRY_IMAGE:$DOCKER_TAG . - docker push $CI_REGISTRY_IMAGE:$DOCKER_TAG rules: - - if: $CI_COMMIT_BRANCH == 'master' || $CI_COMMIT_BRANCH == 'dev' - exists: - - Dockerfile - + - exists: + - Dockerfile.alpine # Build the Debian Docker image ncc-docker-build-debian: image: docker:latest - stage: build-docker + stage: build-docker-debian services: - docker:dind before_script: - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY script: - | - if [[ ! -z "$CI_COMMIT_TAG" ]]; then + if [[ "$CI_COMMIT_BRANCH" == "master" ]]; then + DOCKER_TAG="latest-debian" + elif [[ ! -z "$CI_COMMIT_TAG" ]]; then DOCKER_TAG="$CI_COMMIT_TAG-debian" else DOCKER_TAG="$CI_COMMIT_REF_SLUG-debian" @@ -91,8 +93,7 @@ ncc-docker-build-debian: - docker build -f Dockerfile.debian -t $CI_REGISTRY_IMAGE:$DOCKER_TAG . - docker push $CI_REGISTRY_IMAGE:$DOCKER_TAG rules: - - if: $CI_COMMIT_BRANCH == 'master' || $CI_COMMIT_BRANCH == 'dev' - exists: + - exists: - Dockerfile.debian # Publish the tarball and Debian package to the GitLab Package Registry diff --git a/Dockerfile.alpine b/Dockerfile.alpine new file mode 100644 index 0000000..2386dd0 --- /dev/null +++ b/Dockerfile.alpine @@ -0,0 +1,66 @@ +# Copyright 2022-2023 Nosial - All Rights Reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the +# Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# ncc in Docker +# +# This image is intended to be used as a base for projects using ncc. +# + +# Builder stage: downloads necessary files and serves them on a silver platter. +FROM php:8.2-fpm AS builder +ENV GENERIC_BUILD_PATH=/tmp/ncc_build +WORKDIR /tmp + +# Install some stuff the default image doesn't come with +RUN apt-get update -yqq && \ + apt-get install git libpq-dev libzip-dev zip make wget gnupg -yqq + +# Download phive and install phab +RUN wget -O phive.phar https://phar.io/releases/phive.phar && \ + wget -O phive.phar.asc https://phar.io/releases/phive.phar.asc && \ + gpg --keyserver hkps://keys.openpgp.org --recv-keys 0x9D8A98B29B2D5D79 && \ + gpg --verify phive.phar.asc phive.phar && \ + rm phive.phar.asc && chmod +x phive.phar && \ + ./phive.phar install phpab --global --trust-gpg-keys 0x2A8299CE842DD38C + +# Copy the local repository to the image +COPY . /tmp/ncc + +# Build ncc +RUN cd /tmp/ncc && make redist + + +# Main stage: Copies build files and installs all dependencies +FROM php:8.2-fpm-alpine AS production +LABEL maintainer="netkas " +LABEL description="ncc alpine docker image" +ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ + +# Copy downloaded files +COPY --from=builder /tmp/ncc_build/. . + +# Install some stuff the default image doesn't come with +RUN apk update && \ + apk add --no-cache git libpq libzip zip make wget gnupg gcc + +RUN chmod +x /usr/local/bin/install-php-extensions && sync && \ + install-php-extensions zip xsl + +# Install ncc +RUN php INSTALL --auto; cd ../; rm -rf ncc + +# Finalize image +RUN mkdir /app +WORKDIR /app \ No newline at end of file diff --git a/Dockerfile.debian b/Dockerfile.debian index 557f96b..cc8b268 100644 --- a/Dockerfile.debian +++ b/Dockerfile.debian @@ -18,58 +18,49 @@ # This image is intended to be used as a base for projects using ncc. # -# # Builder stage: downloads necessary files and serves them on a silver platter. -# - FROM php:8.2-fpm AS builder +ENV GENERIC_BUILD_PATH=/tmp/ncc_build WORKDIR /tmp # Install some stuff the default image doesn't come with -RUN apt update -yqq; \ - apt install git libpq-dev libzip-dev zip make wget gnupg -yqq +RUN apt-get update -yqq && \ + apt-get install git libpq-dev libzip-dev zip make wget gnupg -yqq # Download phive and install phab -RUN wget -O phive.phar https://phar.io/releases/phive.phar; \ - wget -O phive.phar.asc https://phar.io/releases/phive.phar.asc; \ - gpg --keyserver hkps://keys.openpgp.org --recv-keys 0x9D8A98B29B2D5D79; \ - gpg --verify phive.phar.asc phive.phar; \ - rm phive.phar.asc; chmod +x phive.phar; ./phive.phar install phpab --global --trust-gpg-keys 0x2A8299CE842DD38C +RUN wget -O phive.phar https://phar.io/releases/phive.phar && \ + wget -O phive.phar.asc https://phar.io/releases/phive.phar.asc && \ + gpg --keyserver hkps://keys.openpgp.org --recv-keys 0x9D8A98B29B2D5D79 && \ + gpg --verify phive.phar.asc phive.phar && \ + rm phive.phar.asc && chmod +x phive.phar && \ + ./phive.phar install phpab --global --trust-gpg-keys 0x2A8299CE842DD38C # Copy the local repository to the image COPY . /tmp/ncc -# Download the latest version of ncc (Nosial Code Compiler) +# Build ncc RUN cd /tmp/ncc && make redist -# -# Main stage: Copies downloaded files and installs all -# - -FROM php:8.2-fpm - -# Add extensions +# Main stage: Copies build files and installs all dependencies +FROM php:8.2-fpm AS production +LABEL maintainer="netkas " +LABEL description="ncc debian docker image" ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ # Copy downloaded files -COPY --from=builder /tmp/. . +COPY --from=builder /tmp/ncc_build/. . # Install some stuff the default image doesn't come with -RUN apt update -yqq; \ - apt install git libpq-dev libzip-dev zip make wget gnupg -yqq +RUN apt-get update -yqq && \ + apt-get install -yqq git libpq-dev libzip-dev zip make wget gnupg gcc -yqq -# Install extensions required to run ncc -RUN install-php-extensions mbstring \ - ctype \ - common; \ - # Add git - apt install -y git; \ - # Install phive, phab and ncc; create workdir - chmod +x phive.phar; \ - mv phive.phar /usr/local/bin/phive; \ - phive install phpab --global --trust-gpg-keys 0x2A8299CE842DD38C; \ - cd ncc; php build/src/INSTALL --auto --install-composer; cd ..; rm -rf ncc; \ - mkdir /app +RUN chmod +x /usr/local/bin/install-php-extensions && sync && \ + install-php-extensions zip xsl -WORKDIR /app +# Install ncc +RUN php INSTALL --auto; cd ../; rm -rf ncc + +# Finalize image +RUN mkdir /app +WORKDIR /app \ No newline at end of file diff --git a/Makefile b/Makefile index 4ff1e92..c80b009 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,9 @@ INSTALLER_SRC_PATH := $(SRC_PATH)/installer CONFIG_PATH := $(SRC_PATH)/config BUILD_VERSION := $(shell cat $(SRC_PATH)/ncc/VERSION) BUILD_PATH := build -GENERIC_BUILD_PATH := $(BUILD_PATH)/ncc_$(BUILD_VERSION) +ifndef GENERIC_BUILD_PATH + GENERIC_BUILD_PATH := $(BUILD_PATH)/ncc_$(BUILD_VERSION) +endif TAR_BUILD:= ncc_$(BUILD_VERSION).tar.gz DEBIAN_SRC_PATH := $(SRC_PATH)/debian DEBIAN_BUILD_PATH := $(BUILD_PATH)/debian/ncc_$(BUILD_VERSION)_all @@ -34,8 +36,10 @@ AUTOLOAD_PATHS := $(addprefix $(SRC_PATH)/ncc/ThirdParty/, \ ifndef PHPCC $(error "PHP binary not found. Please install PHP or check your PATH") endif + +# Check if phpab is installed ifndef PHPAB - $(error "phpab (PHP Autoload Builder) binary not found. Please install phpab or check your PATH") + $(error "phpab (PHP Autoload Builder) not found. Please install phpab or check your PATH") endif # Build rules @@ -121,6 +125,10 @@ $(DEBIAN_PACKAGE_BUILD_PATH): debian_prepare .PHONY: deb deb: $(DEBIAN_PACKAGE_BUILD_PATH) +.PHONY: install +install: redist + $(GENERIC_BUILD_PATH)/INSTALL --auto + .PHONY: clean clean: rm -rf $(BUILD_PATH) diff --git a/Dockerfile b/old_docker/Dockerfile similarity index 97% rename from Dockerfile rename to old_docker/Dockerfile index beb4f63..0a9d2fc 100644 --- a/Dockerfile +++ b/old_docker/Dockerfile @@ -65,7 +65,7 @@ RUN install-php-extensions mbstring \ chmod +x phive.phar; \ mv phive.phar /usr/local/bin/phive; \ phive install phpab --global --trust-gpg-keys 0x2A8299CE842DD38C; \ - cd ncc; php build/src/INSTALL --auto --install-composer; cd ..; rm -rf ncc; \ + cd ncc; php build/src/INSTALL --auto; cd ..; rm -rf ncc; \ mkdir /app WORKDIR /app diff --git a/old_docker/Dockerfile.debian b/old_docker/Dockerfile.debian new file mode 100644 index 0000000..8bd1b5a --- /dev/null +++ b/old_docker/Dockerfile.debian @@ -0,0 +1,74 @@ +# Copyright 2022-2023 Nosial - All Rights Reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the +# Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# ncc in Docker +# +# This image is intended to be used as a base for projects using ncc. +# + +# +# Builder stage: downloads necessary files and serves them on a silver platter. +# + +FROM php:8.2-fpm AS builder +WORKDIR /tmp + +# Install some stuff the default image doesn't come with +RUN apt update -yqq; \ + apt install git libpq-dev libzip-dev zip make wget gnupg -yqq + +# Download phive and install phab +RUN wget -O phive.phar https://phar.io/releases/phive.phar; \ + wget -O phive.phar.asc https://phar.io/releases/phive.phar.asc; \ + gpg --keyserver hkps://keys.openpgp.org --recv-keys 0x9D8A98B29B2D5D79; \ + gpg --verify phive.phar.asc phive.phar; \ + rm phive.phar.asc; chmod +x phive.phar; ./phive.phar install phpab --global --trust-gpg-keys 0x2A8299CE842DD38C + +# Copy the local repository to the image +COPY . /tmp/ncc + +# Download the latest version of ncc (Nosial Code Compiler) +RUN cd /tmp/ncc && make redist + + +# +# Main stage: Copies downloaded files and installs all +# +FROM php:8.2-fpm + +# Add extensions +ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ + +# Copy downloaded files +COPY --from=builder /tmp/. . + +# Install some stuff the default image doesn't come with +RUN apt update -yqq; \ + apt install git libpq-dev libzip-dev zip make wget gnupg -yqq + +# Install extensions required to run ncc +RUN install-php-extensions mbstring \ + ctype \ + common; \ + # Add git + apt install -y git; \ + # Install phive, phab and ncc; create workdir + chmod +x phive.phar; \ + mv phive.phar /usr/local/bin/phive; \ + phive install phpab --global --trust-gpg-keys 0x2A8299CE842DD38C; \ + cd ncc; php build/src/INSTALL --auto; cd ..; rm -rf ncc; \ + mkdir /app + +WORKDIR /app diff --git a/old_docker/note.txt b/old_docker/note.txt new file mode 100644 index 0000000..59a739d --- /dev/null +++ b/old_docker/note.txt @@ -0,0 +1,2 @@ +These are the old dockerfiles for ncc, they are no longer used. The new dockerfiles are in the root of the repository. +These files are kept for reference and may be removed in the future. \ No newline at end of file