From 3040c0c8b4978414818a1b44e2472d519dbeaf42 Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Mon, 14 Sep 2020 19:30:03 +0300 Subject: [PATCH] Add Dockerfile.server and a github workflow for publishing --- .dockerignore | 21 +++++++++ .github/workflows/docker-image.yml | 73 ++++++++++++++++++++++++++++++ Dockerfile.server | 12 +++++ 3 files changed, 106 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/docker-image.yml create mode 100644 Dockerfile.server diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..8908403ae --- /dev/null +++ b/.dockerignore @@ -0,0 +1,21 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +.eggs/ +parts/ +sdist/ +*.egg-info/ +.installed.cfg +*.egg +randovania/version.py + +# virtualenv +.venv +/venv*/ \ No newline at end of file diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 000000000..805bfce91 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,73 @@ +name: Publish Server Docker image +on: + push: + branches: + - master + tags: + - 'v*.*.*' + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v2 + - + name: Prepare + id: prep + run: | + DOCKER_IMAGE=randovania/server + VERSION=noop + if [ "${{ github.event_name }}" = "schedule" ]; then + VERSION=nightly + elif [[ $GITHUB_REF == refs/tags/* ]]; then + VERSION=${GITHUB_REF#refs/tags/} + elif [[ $GITHUB_REF == refs/heads/* ]]; then + VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g') + if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then + VERSION=edge + fi + elif [[ $GITHUB_REF == refs/pull/* ]]; then + VERSION=pr-${{ github.event.number }} + fi + TAGS="${DOCKER_IMAGE}:${VERSION}" + if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then + MINOR=${VERSION%.*} + MAJOR=${MINOR%.*} + TAGS="$TAGS,${DOCKER_IMAGE}:${MINOR},${DOCKER_IMAGE}:${MAJOR},${DOCKER_IMAGE}:latest" + elif [ "${{ github.event_name }}" = "push" ]; then + TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}" + fi + echo ::set-output name=version::${VERSION} + echo ::set-output name=tags::${TAGS} + echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') + - + name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - + name: Login to DockerHub + if: github.event_name != 'pull_request' + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile.server + platforms: linux/amd64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.prep.outputs.tags }} + labels: | + org.opencontainers.image.created=${{ steps.prep.outputs.created }} + org.opencontainers.image.source=${{ github.repositoryUrl }} + org.opencontainers.image.version=${{ steps.prep.outputs.version }} + org.opencontainers.image.revision=${{ github.sha }} + org.opencontainers.image.licenses=${{ github.event.repository.license.name }} \ No newline at end of file diff --git a/Dockerfile.server b/Dockerfile.server new file mode 100644 index 000000000..510ba1513 --- /dev/null +++ b/Dockerfile.server @@ -0,0 +1,12 @@ +FROM python:3.7 + +WORKDIR /usr/src/app + +COPY requirements-setuptools.txt ./ +RUN pip install --no-cache-dir -r requirements-setuptools.txt + +COPY . . +RUN pip install --no-cache-dir -e .[server] -c requirements.txt + +VOLUME ["/data"] +CMD ["python", "-m", "randovania", "multiworld", "server"] \ No newline at end of file