Initial Dockerfile and Pipeline

This commit is contained in:
Thomas Ganter 2021-02-14 00:33:36 +01:00
parent fd24e3bd62
commit c81053ccec
2 changed files with 108 additions and 0 deletions

91
.gitlab-ci.yml Normal file
View file

@ -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 klappts 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

17
Dockerfile Normal file
View file

@ -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