From d815605b6fc76b3512fba2fd8d07a6cc491153f6 Mon Sep 17 00:00:00 2001 From: Andy Augustin Date: Sat, 16 Mar 2024 12:11:34 +0100 Subject: [PATCH] chore(#502): :technologist: merge Dockerfiles Signed-off-by: Andy Augustin --- .github/workflows/push_docker.yml | 26 ++++++++++++++++--- Dockerfile | 43 ++++++++++++++++++++++++------- Makefile | 2 +- docker-compose.yml | 5 ++-- src/.dockerignore | 1 - src/Dockerfile | 32 ----------------------- 6 files changed, 60 insertions(+), 49 deletions(-) delete mode 100644 src/.dockerignore delete mode 100644 src/Dockerfile diff --git a/.github/workflows/push_docker.yml b/.github/workflows/push_docker.yml index 39ea2833..6bdc27a1 100644 --- a/.github/workflows/push_docker.yml +++ b/.github/workflows/push_docker.yml @@ -31,6 +31,7 @@ jobs: strategy: matrix: variant: ["actions-template-sync"] + target: ["prod", "dev"] steps: - name: checkout @@ -56,11 +57,30 @@ jobs: andyAugustin/${{ matrix.variant }} ghcr.io/AndreasAugustin/${{ matrix.variant }} tags: | - type=semver,pattern={{raw}},value=${{ inputs.tag }} - - name: Build and push ${{ matrix.variant }} + type=semver,pattern={{raw}},value=${{ inputs.tag }}${{ matrix.target == 'dev' && '-dev' || '' }} + - name: Build ${{ matrix.variant }} uses: docker/build-push-action@v5 with: - context: ./src/ + context: . + target: ${{ matrix.target }} + load: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + - name: run tests + run: | + echo "Install container tools" + curl -LO https://storage.googleapis.com/container-structure-test/latest/container-structure-test-linux-amd64 \ + && chmod +x container-structure-test-linux-amd64 \ + && sudo mv container-structure-test-linux-amd64 /usr/local/bin/container-structure-test + echo "Run tests" + container-structure-test test \ + --image ${{ matrix.variant }}:${{ steps.meta.outputs.tags }} \ + --config src/test-config.yaml + - name: push ${{ matrix.variant }} + uses: docker/build-push-action@v5 + with: + context: . + target: ${{ matrix.target }} push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index 1d8a8b68..f764ad66 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,28 @@ +######################################## +# prod image ####################################### -# image for dev build environment -###################################### -FROM alpine:3.19.1 as dev +FROM alpine:3.19.1 as prod ARG GH_CLI_VER=2.44.1 +# TODO(anau) change user +ARG GITHUB_URL="https://github.com/AndreasAugustin/actions-template-sync" + +# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys +LABEL org.opencontainers.image.url="${GITHUB_URL}" +LABEL org.opencontainers.image.documentation="${GITHUB_URL}/README.md" +LABEL org.opencontainers.image.source="${GITHUB_URL}" +LABEL org.opencontainers.image.licenses="MIT" +LABEL org.opencontainers.image.authors="andyAugustin" +LABEL org.opencontainers.image.title="actions-template-sync image" +LABEL org.opencontainers.image.description="contains actions-template-sync" + # install packages -RUN apk add --update --no-cache bash make git zsh curl tmux musl openssh git-lfs vim yq gnupg tig +RUN apk add --update --no-cache bash git curl musl openssh git-lfs yq gnupg RUN wget https://github.com/cli/cli/releases/download/v${GH_CLI_VER}/gh_${GH_CLI_VER}_linux_386.tar.gz -O ghcli.tar.gz RUN tar --strip-components=1 -xf ghcli.tar.gz -# Make zsh your default shell for tmux -RUN echo "set-option -g default-shell /bin/zsh" >> /root/.tmux.conf - -# install oh-my-zsh -RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" - ADD src/*.sh /bin/ RUN chmod +x /bin/entrypoint.sh \ && chmod +x /bin/sync_template.sh \ @@ -26,8 +32,25 @@ RUN chmod +x /bin/entrypoint.sh \ RUN mkdir -p /root/.ssh \ && ssh-keyscan -t rsa github.com >> /root/.ssh/known_hosts +ENTRYPOINT ["/bin/bash", "/bin/entrypoint.sh"] +####################################### +# image for dev build environment +###################################### +FROM prod as dev + +# install packages +RUN apk add --update --no-cache make zsh tmux vim tig + +# Make zsh your default shell for tmux +RUN echo "set-option -g default-shell /bin/zsh" >> /root/.tmux.conf + +# install oh-my-zsh +RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" + WORKDIR /app +ENTRYPOINT ["/bin/zsh"] + ####################################### # image for creating the documentation ###################################### diff --git a/Makefile b/Makefile index 5060ec00..c2c6c052 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ markdownlint: ## Validate markdown files .PHONY: zsh zsh: ## open dev container with build environment - docker-compose run --service-ports dev /bin/zsh + docker-compose run --service-ports dev .PHONY: prod prod: ## run the prod docker image with bash diff --git a/docker-compose.yml b/docker-compose.yml index 2ab78b42..ac235f88 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3.7' +version: "3.7" services: dev: @@ -26,6 +26,7 @@ services: prod: build: - context: ./src/ + context: . + target: prod tty: true entrypoint: ["/bin/bash"] diff --git a/src/.dockerignore b/src/.dockerignore deleted file mode 100644 index 1ba994f2..00000000 --- a/src/.dockerignore +++ /dev/null @@ -1 +0,0 @@ -test-config.yaml diff --git a/src/Dockerfile b/src/Dockerfile deleted file mode 100644 index 34fd654a..00000000 --- a/src/Dockerfile +++ /dev/null @@ -1,32 +0,0 @@ -FROM alpine:3.19.1 - -ARG GH_CLI_VER=2.44.1 - -# TODO(anau) change user -ARG GITHUB_URL="https://github.com/AndreasAugustin/actions-template-sync" - -# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys -LABEL org.opencontainers.image.url="${GITHUB_URL}" -LABEL org.opencontainers.image.documentation="${GITHUB_URL}/README.md" -LABEL org.opencontainers.image.source="${GITHUB_URL}" -LABEL org.opencontainers.image.licenses="MIT" -LABEL org.opencontainers.image.authors="andyAugustin" -LABEL org.opencontainers.image.title="actions-template-sync image" -LABEL org.opencontainers.image.description="contains actions-template-sync" - -# install packages -RUN apk add --update --no-cache bash git curl musl openssh git-lfs yq gnupg tig - -RUN wget https://github.com/cli/cli/releases/download/v${GH_CLI_VER}/gh_${GH_CLI_VER}_linux_386.tar.gz -O ghcli.tar.gz -RUN tar --strip-components=1 -xf ghcli.tar.gz - -ADD *.sh /bin/ -RUN chmod +x /bin/entrypoint.sh \ - && chmod +x /bin/sync_template.sh \ - && chmod +x /bin/sync_common.sh \ - && chmod +x /bin/gpg_no_tty.sh - -RUN mkdir -p /root/.ssh \ - && ssh-keyscan -t rsa github.com >> /root/.ssh/known_hosts - -ENTRYPOINT ["/bin/bash", "/bin/entrypoint.sh"]