diff --git a/.github/workflows/push_docker.yml b/.github/workflows/push_docker.yml index 39ea2833..580120f3 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 @@ -53,14 +54,38 @@ jobs: uses: docker/metadata-action@v5 with: images: | - andyAugustin/${{ matrix.variant }} - ghcr.io/AndreasAugustin/${{ matrix.variant }} + 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: install container test tools + 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 + - name: test docker image + run: | + echo "Run tests" + container-structure-test test \ + --image andyaugustin/${{ matrix.variant }}:${{ inputs.tag }}${{ matrix.target == 'dev' && '-dev' || '' }}\ + --config docker-test-config.yml + container-structure-test test \ + --image ghcr.io/andreasaugustin/${{ matrix.variant }}:${{ inputs.tag }}${{ matrix.target == 'dev' && '-dev' || '' }}\ + --config docker-test-config.yml + - 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/.github/workflows/release_test_docker_images.yml b/.github/workflows/release_test_docker_images.yml index b5f5e115..78a1bfa3 100644 --- a/.github/workflows/release_test_docker_images.yml +++ b/.github/workflows/release_test_docker_images.yml @@ -60,4 +60,4 @@ jobs: echo "Run tests" container-structure-test test \ --image ${{ matrix.docker-image }}:${{ inputs.tag }} \ - --config src/test-config.yaml + --config docker-test-config.yml 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/README.md b/README.md index 30b82b5d..10c604df 100644 --- a/README.md +++ b/README.md @@ -574,6 +574,7 @@ There are other great tools available within GitHub. Here you can find a compari | ignore files | :heavy_check_mark: | :x: | :x: | :heavy_check_mark: | | creates a PR | :heavy_check_mark: | :heavy_check_mark: | :x: | :heavy_check_mark: | | sign commits | :heavy_check_mark: | :x: | :x: | :x: | +| docker images available | :heavy_check_mark: | :x: | :x: | :x: | | remarks | The action is placed within the target repositories | The action is placed within the target repositories | CLI meant for local use | The action will be based within the base repository with a list of dependent repositories | ## DEV 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/test-config.yaml b/docker-test-config.yml similarity index 100% rename from src/test-config.yaml rename to docker-test-config.yml 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"]