From 2223baa5b7635d72e458a2bf2b06fc212180dd31 Mon Sep 17 00:00:00 2001 From: Tine Jozelj Date: Sat, 26 Dec 2020 15:00:26 +0100 Subject: [PATCH] feat(workspace): switch to alpine from ubuntu --- .../workflows/{ubuntu.yaml => workspace.yaml} | 12 ++-- .gitignore | 2 +- Dockerfile.ubuntu => Dockerfile | 63 +++++++------------ Makefile | 6 +- README.md | 2 +- templates/actions/workspace.yaml.tmpl | 4 +- workspace.toml | 9 +-- 7 files changed, 42 insertions(+), 56 deletions(-) rename .github/workflows/{ubuntu.yaml => workspace.yaml} (91%) rename Dockerfile.ubuntu => Dockerfile (66%) diff --git a/.github/workflows/ubuntu.yaml b/.github/workflows/workspace.yaml similarity index 91% rename from .github/workflows/ubuntu.yaml rename to .github/workflows/workspace.yaml index b177a8b..9f0b028 100644 --- a/.github/workflows/ubuntu.yaml +++ b/.github/workflows/workspace.yaml @@ -1,4 +1,4 @@ -name: ubuntu +name: workspace on: schedule: @@ -11,7 +11,7 @@ on: - v* jobs: - ubuntu: + workspace: runs-on: ubuntu-latest steps: - name: Checkout @@ -19,7 +19,7 @@ jobs: - name: Prepare id: prepare run: | - DOCKER_IMAGE=ghcr.io/mentos1386/workspace-ubuntu + DOCKER_IMAGE=ghcr.io/mentos1386/workspace DOCKER_PLATFORMS=linux/amd64,linux/arm64 VERSION=edge @@ -43,14 +43,14 @@ jobs: --build-arg VCS_REF=${GITHUB_SHA::8} \ --cache-from "type=local,src=/tmp/.buildx-cache" \ --cache-to "type=local,dest=/tmp/.buildx-cache" \ - ${TAGS} --file ./Dockerfile.ubuntu . + ${TAGS} --file ./Dockerfile . - name: Cache Docker layers uses: actions/cache@v2 with: path: /tmp/.buildx-cache - key: ${{ runner.os }}-ubuntu-${{ github.sha }} + key: ${{ runner.os }}-workspace-${{ github.sha }} restore-keys: | - ${{ runner.os }}-ubuntu- + ${{ runner.os }}-workspace- - name: Set up QEMU uses: docker/setup-qemu-action@v1 - name: Set up Docker Buildx diff --git a/.gitignore b/.gitignore index 7566579..783cd5b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -.swp +*.swp diff --git a/Dockerfile.ubuntu b/Dockerfile similarity index 66% rename from Dockerfile.ubuntu rename to Dockerfile index 7770960..c31336f 100644 --- a/Dockerfile.ubuntu +++ b/Dockerfile @@ -1,31 +1,32 @@ # vim: set fenc=utf-8 ts=2 sw=2 sts=2 et ft=Dockerfile : -FROM ubuntu:20.10 +FROM alpine:3.12 LABEL maintainer="Tine Jozelj " LABEL org.opencontainers.image.source https://github.com/mentos1386/workspace ARG SSH_USER="${SSH_USER:-tine}" -ENV LANG en_US.UTF-8 -ENV LANGUAGE en_US:en -ENV LC_ALL en_US.UTF-8 +RUN apk --update --no-cache add bash -SHELL ["/bin/bash", "-c"] +SHELL ["bash", "-c"] -RUN set -ueox pipefail \ -&& DEBIAN_FRONTEND=noninteractive \ -&& apt-get -yqq update \ -&& apt-get -yqq --no-install-recommends --no-install-suggests install \ - ca-certificates \ - locales \ - perl \ +RUN apk --update --no-cache add \ + git \ + mosh \ + neovim \ openssh-server \ - psmisc \ -&& sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen \ -&& locale-gen \ -&& adduser --quiet --gecos '' --disabled-password --add_extra_groups "${SSH_USER}" \ -&& apt-get -yqq clean all \ -&& rm -rf /var/lib/apt/lists/* \ + tmux \ + zsh \ +&& adduser -D "${SSH_USER}" -s /bin/bash \ +&& ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa \ +&& ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa \ +&& ssh-keygen -f /etc/ssh/ssh_host_ecdsa_key -N '' -t ecdsa \ +&& ssh-keygen -f /etc/ssh/ssh_host_ed25519_key -N '' -t ed25519 \ +&& chown root:root /etc/ssh \ +&& chmod 0600 /etc/ssh/* \ +&& mkdir -p /root/.ssh \ +&& chmod 0700 /root/.ssh \ +&& rm -rf /var/cache/apk/* \ /tmp/* \ /var/tmp/* @@ -36,27 +37,13 @@ RUN touch /etc/ssh/sshd_config.d/custom \ && echo "UsePAM no" >> /etc/ssh/sshd_config.d/custom \ && echo "X11Forwarding no" >> /etc/ssh/sshd_config.d/custom -# Install available packages -RUN set -ueox pipefail \ -&& DEBIAN_FRONTEND=noninteractive \ -&& apt-get -yqq update \ -&& apt-get -yqq --no-install-recommends --no-install-suggests install \ - git \ - tmux \ - vim \ - zsh \ -&& apt-get -yqq clean all \ -&& rm -rf /var/lib/apt/lists/* \ - /tmp/* \ - /var/tmp/* - -# Install other packages +# install tools COPY --from=ghcr.io/mentos1386/starship:0.47.0 /usr/local/bin/starship /usr/local/bin/starship COPY --from=ghcr.io/mentos1386/kubectl:1.20.0 /usr/local/bin/kubectl /usr/local/bin/kubectl COPY --from=ghcr.io/mentos1386/glow:1.3.0 /usr/local/bin/glow /usr/local/bin/glow -COPY --from=ghcr.io/mentos1386/mosh:master /usr/local/bin/mosh /usr/local/bin/mosh -COPY --from=ghcr.io/mentos1386/mosh:master /usr/local/bin/mosh-server /usr/local/bin/mosh-server -COPY --from=ghcr.io/mentos1386/mosh:master /usr/local/bin/mosh-client /usr/local/bin/mosh-client +COPY --from=ghcr.io/mentos1386/mosh:master /usr/bin/mosh /usr/bin/mosh +COPY --from=ghcr.io/mentos1386/mosh:master /usr/bin/mosh-server /usr/bin/mosh-server +COPY --from=ghcr.io/mentos1386/mosh:master /usr/bin/mosh-client /usr/bin/mosh-client # Golang COPY --from=golang:1.15.6 --chown=${SSH_USER} /usr/local/go /home/${SSH_USER}/.go ENV PATH=/home/${SSH_USER}/.go/bin:$PATH @@ -90,16 +77,14 @@ RUN mkdir -p "/home/${SSH_USER}/.config" \ && ln -s "/home/${SSH_USER}/.dotfiles/nvim" "/home/${SSH_USER}/.config/nvim" \ && ln -s "/home/${SSH_USER}/.dotfiles/nvim/vimrc" "/home/${SSH_USER}/.vimrc" \ && git clone --depth 1 https://github.com/Shougo/dein.vim "/home/${SSH_USER}/.cache/vim/dein/repos/github.com/Shougo/dein.vim" \ -&& vim -V1 -es -i NONE -N --noplugin -u "/home/${SSH_USER}/.config/nvim/config/vimrc" \ +&& nvim -V1 -es -i NONE -N --noplugin -u "/home/${SSH_USER}/.config/nvim/config/vimrc" \ -c "try | call dein#clear_state() | call dein#update() | finally | messages | qall! | endtry" # SSH RUN mkdir -p /home/${SSH_USER}/.ssh \ && ln -s /home/${SSH_USER}/.dotfiles/ssh/authorized_keys /home/${SSH_USER}/.ssh/authorized_keys -# Start SSH Daemon USER root EXPOSE 22/tcp EXPOSE 22022/udp -RUN mkdir -p /run/sshd CMD ["/usr/sbin/sshd", "-D", "-e", "-f", "/etc/ssh/sshd_config"] diff --git a/Makefile b/Makefile index c4bdd8c..65a8c49 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ PROGRESS=plain build: - @docker buildx build --load -t ${REGISTRY}/workspace-ubuntu:edge -f Dockerfile.ubuntu . + @docker buildx build --load -t ${REGISTRY}/workspace:edge -f Dockerfile . build-package-starship: @docker buildx build --load -t ${REGISTRY}/starship:0.47.0 -f packages/Dockerfile.starship packages/ @@ -21,7 +21,7 @@ build-packages: package-kubectl package-starship template: @go run ./main.go template package-action > .github/workflows/packages.yaml - @go run ./main.go template ubuntu-action > .github/workflows/ubuntu.yaml + @go run ./main.go template workspace-action > .github/workflows/workspace.yaml pull: @docker pull ghcr.io/mentos1386/workspace-ubuntu:edge @@ -29,5 +29,5 @@ pull: @docker pull ghcr.io/mentos1386/kubectl:1.20.0 run: - @docker run -it --rm --workdir /home/tine --user tine ghcr.io/mentos1386/workspace-ubuntu:edge zsh + @docker run -it --rm --workdir /home/tine --user tine ghcr.io/mentos1386/workspace:edge zsh diff --git a/README.md b/README.md index 629b7f8..f245e17 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![Ubuntu](https://github.com/mentos1386/workspace/workflows/ubuntu/badge.svg) +![Workspace](https://github.com/mentos1386/workspace/workflows/workspace/badge.svg) ![Packages](https://github.com/mentos1386/workspace/workflows/packages/badge.svg) my workspace as a docker container diff --git a/templates/actions/workspace.yaml.tmpl b/templates/actions/workspace.yaml.tmpl index 472fc43..c43c589 100644 --- a/templates/actions/workspace.yaml.tmpl +++ b/templates/actions/workspace.yaml.tmpl @@ -19,7 +19,7 @@ jobs: - name: Prepare id: prepare run: | - DOCKER_IMAGE=[[[.repository]]]/workspace-[[[.name]]] + DOCKER_IMAGE=[[[.repository]]]/[[[.name]]] DOCKER_PLATFORMS=[[[.platforms]]] VERSION=edge @@ -43,7 +43,7 @@ jobs: --build-arg VCS_REF=${GITHUB_SHA::8} \ --cache-from "type=local,src=/tmp/.buildx-cache" \ --cache-to "type=local,dest=/tmp/.buildx-cache" \ - ${TAGS} --file ./Dockerfile.[[[.name]]] . + ${TAGS} --file ./[[[.dockerfile]]] . - name: Cache Docker layers uses: actions/cache@v2 with: diff --git a/workspace.toml b/workspace.toml index 87a6bd0..bb66c92 100644 --- a/workspace.toml +++ b/workspace.toml @@ -1,10 +1,11 @@ ## -# Ubuntu -[templates."ubuntu-action"] +# Workspace +[templates."workspace-action"] template = "templates/actions/workspace.yaml.tmpl" -[templates."ubuntu-action".vars] -name = "ubuntu" +[templates."workspace-action".vars] +name = "workspace" +dockerfile = "Dockerfile" repository = "ghcr.io/mentos1386" platforms = "linux/amd64,linux/arm64"