Chore: Docker (#1696)

* Add Docker builds

* Add support for push to all branches

* Fix some Docker bugs
This commit is contained in:
Aaron Dewes 2022-05-04 10:23:35 +02:00 committed by GitHub
parent 9dbde39c2d
commit 4646025790
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 144 additions and 11 deletions

View file

@ -1,11 +0,0 @@
.env
pyinstaller
.git
release
docs
.vscode
tests
docker
.pytest_cache
build
dist

1
.dockerignore Symbolic link
View file

@ -0,0 +1 @@
.gitignore

43
.github/workflows/docker-push.yml vendored Normal file
View file

@ -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" ./

42
.github/workflows/docker-tag.yml vendored Normal file
View file

@ -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" ./

58
Dockerfile Normal file
View file

@ -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"]