From 4ec37438b3e046a34c4779cf875fdb938a49d8f4 Mon Sep 17 00:00:00 2001 From: Rick Barenthin Date: Mon, 1 Aug 2022 14:24:25 +0200 Subject: [PATCH] feat: inital version of a static webserver --- .dockerignore | 1 + .drone.yml | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 31 +++++++++++++ LICENSE | 2 +- README.md | 1 + 5 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 .drone.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..f59ec20 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +* \ No newline at end of file diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..caf6d48 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,120 @@ +--- +kind: pipeline +type: docker +name: main + +steps: + - name: Fetch tags + image: alpine/git + commands: + - git fetch --tags + - name: Update version and changelog + image: registry.riba-interactive.de/conventi:0.1.0 + - name: Commit changelog updates + image: alpine/git + commands: + - git add . + - git commit -m "version and changelog update [CI SKIP]" + - git push origin $DRONE_TARGET_BRANCH + - name: Tag commit + image: registry.riba-interactive.de/conventi:0.1.0 + commands: + - export VERSION=$(conventi.sh get_version) + - git tag -am "Tagging new version $VERSION" "$VERSION" + - git push origin "$VERSION" + +trigger: + branch: + - main + event: + - push + +image_pull_secrets: + - dockerconfig +--- +kind: pipeline +type: docker +name: tag + +steps: + - name: Build release + image: docker:dind + volumes: + - name: dockersock + path: /var/run + environment: + DOCKER_USER: + from_secret: docker_user + DOCKER_PASSWORD: + from_secret: docker_password + commands: + - sleep 5 # give docker enough time to start + - echo "$DOCKER_PASSWORD" | docker login --username $DOCKER_USER --password-stdin registry.riba-interactive.de + - docker pull registry.riba-interactive.de/statically:latest || true + - DOCKER_BUILDKIT=1 docker build --cache-from registry.riba-interactive.de/statically:latest --tag registry.riba-interactive.de/statically:latest . + - docker tag registry.riba-interactive.de/statically:latest registry.riba-interactive.de/statically:$DRONE_TAG + - docker push --all-tags registry.riba-interactive.de/statically + +trigger: + event: + - tag + +services: + - name: docker + image: docker:dind + privileged: true + volumes: + - name: dockersock + path: /var/run + +volumes: + - name: dockersock + temp: {} + +image_pull_secrets: + - dockerconfig +--- +kind: pipeline +type: docker +name: Build and Test + +steps: + - name: Build image + image: docker:dind + volumes: + - name: dockersock + path: /var/run + environment: + DOCKER_USER: + from_secret: docker_user + DOCKER_PASSWORD: + from_secret: docker_password + commands: + - sleep 5 # give docker enough time to start + - echo "$DOCKER_PASSWORD" | docker login --username $DOCKER_USER --password-stdin registry.riba-interactive.de + - docker pull registry.riba-interactive.de/statically:latest || true + - DOCKER_BUILDKIT=1 docker build --cache-from registry.riba-interactive.de/statically:latest --tag registry.riba-interactive.de/statically:latest . + - docker tag registry.riba-interactive.de/statically:latest registry.riba-interactive.de/statically:build-$DRONE_BUILD_NUMBER + - docker push --all-tags registry.riba-interactive.de/statically + +trigger: + branch: + - develop + - feature/* + - bugfix/* + +services: + - name: docker + image: docker:dind + privileged: true + volumes: + - name: dockersock + path: /var/run + +volumes: + - name: dockersock + temp: {} + +image_pull_secrets: + - dockerconfig +... \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..30bec3b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +FROM alpine:3.16.0 AS builder + +ARG THTTPD_VERSION=2.29 + +RUN apk add gcc musl-dev make +RUN wget http://www.acme.com/software/thttpd/thttpd-${THTTPD_VERSION}.tar.gz \ + && tar xzf thttpd-${THTTPD_VERSION}.tar.gz \ + && mv /thttpd-${THTTPD_VERSION} /thttpd +RUN cd /thttpd \ + && ./configure \ + && make CCOPT='-O2 -s -static' thttpd + +RUN adduser -D www --home /var/www + + +FROM scratch + +EXPOSE 3000 + +COPY --from=builder /etc/passwd /etc/passwd +COPY --from=builder /thttpd/thttpd /usr/local/bin/ + +USER www +WORKDIR /var/www/htdocs + +# Copy the static website +# Use the .dockerignore file to control what ends up inside the image! +COPY . . + +# Run thttpd +CMD ["/usr/local/bin/thttpd", "-D", "-h", "0.0.0.0", "-p", "3000", "-d", "/var/www/htdocs", "-u", "www", "-l", "-", "-M", "60"] \ No newline at end of file diff --git a/LICENSE b/LICENSE index e06aa93..17aef81 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) year copyright holder. All Rights Reserved. +Copyright (c) 2022 Rick Barenthin. All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/README.md b/README.md index c7ed710..5bb6a17 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # statically +[![Build Status](https://drone.riba-interactive.de/api/badges/rick/statically/status.svg)](https://drone.riba-interactive.de/rick/statically) \ No newline at end of file