Skip to content

Commit

Permalink
Add slim version dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
ysde committed Mar 25, 2023
1 parent 67f6294 commit f7dfd70
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 26 deletions.
22 changes: 19 additions & 3 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,30 @@ jobs:

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
uses: docker/metadata-action@v4
with:
images: ysde/docker-grafana-backup-tool

- name: Extract metadata (tags, labels) for Docker (Slim version)
id: meta_slim
uses: docker/metadata-action@v4
with:
images: ysde/docker-grafana-backup-tool
flavor: |
latest=auto
suffix=-slim,onlatest=true
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Build and push Docker image slim version
uses: docker/build-push-action@v4
with:
file: ./DockerfileSlim
push: true
tags: ${{ steps.meta_slim.outputs.tags }}
labels: ${{ steps.meta_slim.outputs.labels }}
28 changes: 5 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,20 @@ FROM alpine:latest

LABEL maintainer="[email protected]"

ARG UID=1337
ARG GID=1337
ENV RESTORE false
ENV ARCHIVE_FILE ""

ENV DEV_PACKAGES="\
gcc \
libc-dev \
libffi-dev \
py3-pip \
python3-dev \
"
RUN echo "@edge http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
&& apk --no-cache add python3-dev libffi-dev gcc libc-dev py3-pip py3-cffi py3-cryptography ca-certificates bash

ENV PACKAGES="\
bash \
ca-certificates \
py3-cffi \
py3-cryptography \
py3-six \
"
WORKDIR /opt/grafana-backup-tool
ADD . /opt/grafana-backup-tool

RUN chmod -R a+r /opt/grafana-backup-tool \
&& find /opt/grafana-backup-tool -type d -print0 | xargs -0 chmod a+rx

RUN echo "@edge http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
&& apk add --no-cache --virtual build-deps ${DEV_PACKAGES} \
&& apk add --no-cache ${PACKAGES} \
&& pip3 --no-cache-dir install . \
&& chown -R ${UID}:${GID} /opt/grafana-backup-tool \
&& apk del build-deps
RUN pip3 --no-cache-dir install .

USER ${UID}
RUN chown -R 1337:1337 /opt/grafana-backup-tool
USER 1337
CMD sh -c 'if [ "$RESTORE" = true ]; then if [ ! -z "$AWS_S3_BUCKET_NAME" ] || [ ! -z "$AZURE_STORAGE_CONTAINER_NAME" ]; then grafana-backup restore $ARCHIVE_FILE; else grafana-backup restore _OUTPUT_/$ARCHIVE_FILE; fi else grafana-backup save; fi'
39 changes: 39 additions & 0 deletions DockerfileSlim
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
FROM alpine:latest

LABEL maintainer="[email protected]"

ARG UID=1337
ARG GID=1337
ENV RESTORE false
ENV ARCHIVE_FILE ""

ENV DEV_PACKAGES="\
gcc \
libc-dev \
libffi-dev \
py3-pip \
python3-dev \
"

ENV PACKAGES="\
bash \
ca-certificates \
py3-cffi \
py3-cryptography \
py3-six \
"
WORKDIR /opt/grafana-backup-tool
ADD . /opt/grafana-backup-tool

RUN chmod -R a+r /opt/grafana-backup-tool \
&& find /opt/grafana-backup-tool -type d -print0 | xargs -0 chmod a+rx

RUN echo "@edge http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
&& apk add --no-cache --virtual build-deps ${DEV_PACKAGES} \
&& apk add --no-cache ${PACKAGES} \
&& pip3 --no-cache-dir install . \
&& chown -R ${UID}:${GID} /opt/grafana-backup-tool \
&& apk del build-deps

USER ${UID}
CMD sh -c 'if [ "$RESTORE" = true ]; then if [ ! -z "$AWS_S3_BUCKET_NAME" ] || [ ! -z "$AZURE_STORAGE_CONTAINER_NAME" ]; then grafana-backup restore $ARCHIVE_FILE; else grafana-backup restore _OUTPUT_/$ARCHIVE_FILE; fi else grafana-backup save; fi'

0 comments on commit f7dfd70

Please sign in to comment.