From 4646025790a61346ae3b1294dc9379c55144b21a Mon Sep 17 00:00:00 2001 From: Aaron Dewes Date: Wed, 4 May 2022 10:23:35 +0200 Subject: [PATCH] Chore: Docker (#1696) * Add Docker builds * Add support for push to all branches * Fix some Docker bugs --- .dockerignore | 12 +------ .github/workflows/docker-push.yml | 43 +++++++++++++++++++++++ .github/workflows/docker-tag.yml | 42 ++++++++++++++++++++++ Dockerfile | 58 +++++++++++++++++++++++++++++++ 4 files changed, 144 insertions(+), 11 deletions(-) mode change 100644 => 120000 .dockerignore create mode 100644 .github/workflows/docker-push.yml create mode 100644 .github/workflows/docker-tag.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index 130546a5b..000000000 --- a/.dockerignore +++ /dev/null @@ -1,11 +0,0 @@ -.env -pyinstaller -.git -release -docs -.vscode -tests -docker -.pytest_cache -build -dist \ No newline at end of file diff --git a/.dockerignore b/.dockerignore new file mode 120000 index 000000000..3e4e48b0b --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.gitignore \ No newline at end of file diff --git a/.github/workflows/docker-push.yml b/.github/workflows/docker-push.yml new file mode 100644 index 000000000..dc522cc68 --- /dev/null +++ b/.github/workflows/docker-push.yml @@ -0,0 +1,43 @@ +name: Build Docker container on push + +on: + push: + branches: + - "*" + +jobs: + build: + name: Build image + runs-on: ubuntu-20.04 + + steps: + - name: Checkout project + uses: actions/checkout@v2 + + - name: Set env variables + run: | + echo "BRANCH=$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//-/g')" >> $GITHUB_ENV + REPO_OWNER=${{ github.repository_owner }} + echo "IMAGE_NAME=${REPO_OWNER,,}/${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + id: qemu + + - name: Setup Docker buildx action + uses: docker/setup-buildx-action@v1 + id: buildx + + - name: Run Docker buildx + run: | + docker buildx build \ + --platform linux/amd64,linux/arm64 \ + --tag ghcr.io/$IMAGE_NAME:$BRANCH \ + --output "type=registry" ./ diff --git a/.github/workflows/docker-tag.yml b/.github/workflows/docker-tag.yml new file mode 100644 index 000000000..ac8208ff9 --- /dev/null +++ b/.github/workflows/docker-tag.yml @@ -0,0 +1,42 @@ +name: Build Docker container on tag + +on: + push: + tags: + - v[0-9]+.[0-9]+.[0-9]+ + - v[0-9]+.[0-9]+.[0-9]+-* + +jobs: + build: + name: Build image + runs-on: ubuntu-20.04 + + steps: + - name: Checkout project + uses: actions/checkout@v2 + + - name: Set env variables + run: | + echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV + REPO_OWNER=${{ github.repository_owner }} + echo "IMAGE_NAME=${REPO_OWNER,,}/${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Setup Docker buildx action + uses: docker/setup-buildx-action@v1 + + - name: Run Docker buildx + run: | + docker buildx build \ + --platform linux/amd64,linux/arm64 \ + --tag ghcr.io/$IMAGE_NAME:$TAG \ + --output "type=registry" ./ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..032f9d8d7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,58 @@ +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. + +ARG USER=specter +ARG DIR=/data/ + +FROM python:3.9-slim-bullseye AS builder + +ARG VERSION +ARG REPO + +RUN apt update && apt install -y git build-essential libusb-1.0-0-dev libudev-dev libffi-dev libssl-dev rustc cargo + +WORKDIR / + +WORKDIR /specter-desktop + +COPY . . + +RUN pip3 install --upgrade pip +RUN pip3 install babel cryptography +RUN pip3 install . + + +FROM python:3.9-slim-bullseye as final + +ARG USER +ARG DIR + +RUN apt update && apt install -y libusb-1.0-0-dev libudev-dev + +# NOTE: Default GID == UID == 1000 +RUN adduser --disabled-password \ + --home "$DIR" \ + --gecos "" \ + "$USER" + +# Set user +USER $USER + +# Make config directory +RUN mkdir -p "$DIR/.specter/" + + +# Copy over python stuff +COPY --from=builder /usr/local/lib/python3.9 /usr/local/lib/python3.9 +COPY --from=builder /usr/local/bin /usr/local/bin + + +# Expose ports +EXPOSE 25441 25442 25443 + +ENTRYPOINT ["/usr/local/bin/python3", "-m", "cryptoadvance.specter", "server", "--host", "0.0.0.0"]