From c81053ccecd44a6495579defa80078c2a04c04d8 Mon Sep 17 00:00:00 2001 From: Thomas Ganter Date: Sun, 14 Feb 2021 00:33:36 +0100 Subject: [PATCH] Initial Dockerfile and Pipeline --- .gitlab-ci.yml | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 17 ++++++++++ 2 files changed, 108 insertions(+) create mode 100644 .gitlab-ci.yml create mode 100644 Dockerfile diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..5acfdef --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,91 @@ +# Mein Default Pipeline File: +# +# Macht einen einfachen Docker Build +# und pusht das Ergebnis in die Container Registry +# wobei bei nicht getaggten Builds das vorherige Image wieder aus der Registry gelöscht wird. +# + +# Wir verwenden mein Spezial-Docker-Image mit dem „reg“ Tool zum Löschen aus Registries. +image: hub.fami.ga/root/docker:17 + +# Einfache 2-Stage Pipeline +stages: + - build + - push + +variables: + DOCKER_DRIVER: overlay2 + CACHE_IMAGE: /cache + +# Login in der Registry, sonst klappt’s nicht +before_script: + - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY + +# Der Docker Build … +Build: + stage: build + script: + # fetches the latest image (not failing if image is not found) + - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG || true + - docker pull $CI_REGISTRY_IMAGE:latest || true + # + - echo "##### my Environment" && env && which curl && which reg && ls -la /usr/local/bin/ && echo "#####" + - > + docker build + --pull + --build-arg VCS_REF=$CI_COMMIT_SHA + --build-arg VCS_URL=$CI_PROJECT_URL + --cache-from $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG + --cache-from $CI_REGISTRY_IMAGE:latest + --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA + . + - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA + - echo "##### Build done..." + +Clean previous: + stage: build + script: + - echo "before ... ${CI_COMMIT_BEFORE_SHA} ... trying to remove?" + - docker pull hub.fami.ga/root/docker:empty + - docker tag hub.fami.ga/root/docker:empty $CI_REGISTRY_IMAGE:$CI_COMMIT_BEFORE_SHA + - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_BEFORE_SHA + - /usr/local/bin/reg rm -d --auth-url $CI_REGISTRY -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY_IMAGE:$CI_COMMIT_BEFORE_SHA + - echo "##### Cleanup done..." + + +Push slug: + variables: + GIT_STRATEGY: none + stage: push + except: [tags] + script: + - echo "##### Push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA -> $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" + - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA + - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG + - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG + + +Push latest: + variables: + GIT_STRATEGY: none + stage: push + only: [tags] + script: + - echo "##### Push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA -> $CI_REGISTRY_IMAGE:latest" + - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA + - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:latest + - docker push $CI_REGISTRY_IMAGE:latest + + +Push tag: + variables: + GIT_STRATEGY: none + stage: push + only: [tags] + script: + - echo "##### Push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA -> $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG" + - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA + - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG + - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG + + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8e83617 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM alpine:latest as builder + +WORKDIR /work +RUN \ + apk update && \ + apk add curl && \ + curl -L -o master.zip https://github.com/getkirby/plainkit/archive/master.zip && \ + unzip master.zip && \ + cd plainkit-master && \ + rm -rf README.md .editorconfig .gitignore .htaccess composer.json + +############################ + +FROM php:8-fpm-alpine3.13 + +EXPOSE 9000 +COPY --from=builder /work/plainkit-master /site