diff --git a/.github/workflows/build_release.yml b/.github/workflows/build_release.yml new file mode 100644 index 0000000..d954f56 --- /dev/null +++ b/.github/workflows/build_release.yml @@ -0,0 +1,65 @@ +name: Build/Release + +on: + push: + # takes muliple branch names + branches: + - main + - '[0-9][0-9][0-9][0-9].[0-9][0-9].*' # 2021.01.x + tags: + - '[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9]' # 2021.01.01 + + workflow_dispatch: + inputs: + version: + description: 'Version' + required: true + default: 'YYYY.MINOR.MICRO' +env: + REPO_URL: ${{ github.repository }} + +jobs: + build: + # to test a feature, change the repo name to your github id + if: github.repository_owner == 'pushyamig' || github.event_name == 'workflow_dispatch' + runs-on: ubuntu-latest + steps: + + - name: Checkout code + uses: actions/checkout@v4 + + - name: Extract branch name + id: extract_branch + run: echo "BRANCH_NAME=$(basename ${{ github.ref }})" >> $GITHUB_ENV + + - name: build Docker image + run: | + docker build -f Dockerfile . --tag ghcr.io/${{ env.REPO_URL }}:${BRANCH_NAME} + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Push Docker image to GitHub Container Registry + run: | + docker push ghcr.io/${{ env.REPO_URL }}:${BRANCH_NAME} + + release: + # Making sure that release only runs for tag pushes + if: startsWith(github.ref, 'refs/tags/') + needs: build # This ensures the build job finishes successfully before starting this job + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Draft Release + id: create_release + uses: softprops/action-gh-release@v2 + with: + draft: true + prerelease: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index bf1cdaa..9286732 100644 --- a/.gitignore +++ b/.gitignore @@ -124,6 +124,7 @@ venv/ ENV/ env.bak/ venv.bak/ +venv_* # Spyder project settings .spyderproject @@ -261,6 +262,7 @@ dist # Stores VSCode versions used for testing VSCode extensions .vscode-test +.history # yarn v2 .yarn/cache diff --git a/dockerfiles/Dockerfile b/Dockerfile similarity index 71% rename from dockerfiles/Dockerfile rename to Dockerfile index f5f1ad3..233586f 100644 --- a/dockerfiles/Dockerfile +++ b/Dockerfile @@ -1,6 +1,13 @@ -# FROM directive instructing base image to build upon -# This could be used as a base instead: -# https://hub.docker.com/r/nikolaik/python-nodejs +# node-build stage + +FROM node:20-slim AS node-build +WORKDIR /build/ + +COPY frontend . +RUN npm install + +RUN npm run build:frontend + FROM python:3.10-slim # NOTE: requirements.txt not likely to change between dev builds @@ -27,19 +34,26 @@ apt install -y --no-install-recommends libmariadb-dev RUN pip install --no-cache-dir -r requirements.txt -WORKDIR /code/frontend - RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \ - apt install -y nodejs - -COPY /frontend/package*.json /code/frontend -RUN npm install +apt install -y nodejs WORKDIR /code +# Copy only what is needed into /code/ +COPY backend ./backend +COPY templates ./templates +COPY manage.py start_backend.sh ./ + +COPY --from=node-build /build/bundles ./frontend/bundles +COPY --from=node-build /build/webpack-stats.json ./frontend/ +COPY --from=node-build /build/node_modules ./frontend/node_modules + + + # Sets the local timezone of the docker image ARG TZ ENV TZ ${TZ:-America/Detroit} +ENV RUN_FRONTEND ${RUN_FRONTEND:-false} RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone # EXPOSE port 5000 to allow communication to/from server diff --git a/deploy/supervisor_docker.conf b/deploy/supervisor_docker.conf index 2f1f0fe..5905501 100644 --- a/deploy/supervisor_docker.conf +++ b/deploy/supervisor_docker.conf @@ -12,7 +12,7 @@ startsecs=5 startretries=2 [program:frontend] -command=npm run watch +command=bash -c "if [ \"$RUN_FRONTEND\" = \"true\" ]; then npm run watch; else tail -f /dev/null; fi" directory=/code/frontend stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 diff --git a/docker-compose.yml b/docker-compose.yml index 5aacffb..25e1362 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,7 +19,7 @@ services: web: build: context: . - dockerfile: dockerfiles/Dockerfile + dockerfile: Dockerfile args: TZ: ${TZ} volumes: @@ -35,6 +35,7 @@ services: - .env environment: - DEBUG=True + - RUN_FRONTEND=true redis: image: redis:7 volumes: