From 4574378a3f37a79b8dad3af173a25c4d250bbfc2 Mon Sep 17 00:00:00 2001 From: Pushyami Gundala Date: Mon, 2 Dec 2024 10:22:53 -0500 Subject: [PATCH] Fixing the Build using GH --- .github/workflows/build_release.yml | 20 +++++----- .gitignore | 2 + dockerfiles/Dockerfile.prod => Dockerfile | 36 ++++++++++++----- docker-compose-openshift-test.yml | 36 ----------------- docker-compose.yml | 2 +- dockerfiles/Dockerfile | 48 ----------------------- 6 files changed, 41 insertions(+), 103 deletions(-) rename dockerfiles/Dockerfile.prod => Dockerfile (50%) delete mode 100644 docker-compose-openshift-test.yml delete mode 100644 dockerfiles/Dockerfile diff --git a/.github/workflows/build_release.yml b/.github/workflows/build_release.yml index 605564d..2b1554c 100644 --- a/.github/workflows/build_release.yml +++ b/.github/workflows/build_release.yml @@ -6,9 +6,11 @@ on: branches: - main - '[0-9][0-9][0-9][0-9].[0-9][0-9].*' # 2021.01.x + - 'issue_322' + - 'i322_gh_actions' tags: - '[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9]' # 2021.01.01 - + workflow_dispatch: inputs: version: @@ -17,24 +19,24 @@ on: 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 == 'tl-its-umich-edu' || github.event_name == 'workflow_dispatch' + 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 dockerfiles/Dockerfile.prod . --tag ghcr.io/${{ env.REPO_URL }}:${BRANCH_NAME} + docker build -f Dockerfile . --tag ghcr.io/${{ env.REPO_URL }}:${BRANCH_NAME} - name: Login to GitHub Container Registry uses: docker/login-action@v3 @@ -42,14 +44,14 @@ jobs: 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/')' + if: startsWith(github.ref, 'refs/tags/') needs: build # This ensures the build job finishes successfully before starting this job runs-on: ubuntu-latest steps: diff --git a/.gitignore b/.gitignore index 514c6bf..a81656b 100644 --- a/.gitignore +++ b/.gitignore @@ -123,6 +123,7 @@ venv/ ENV/ env.bak/ venv.bak/ +venv_* # Spyder project settings .spyderproject @@ -260,6 +261,7 @@ dist # Stores VSCode versions used for testing VSCode extensions .vscode-test +.history # yarn v2 .yarn/cache diff --git a/dockerfiles/Dockerfile.prod b/Dockerfile similarity index 50% rename from dockerfiles/Dockerfile.prod rename to Dockerfile index 7da2fa5..1bc049b 100644 --- a/dockerfiles/Dockerfile.prod +++ b/Dockerfile @@ -8,20 +8,35 @@ RUN npm install RUN npm run build:frontend -# main stage - -FROM python:3.10-slim-bookworm AS main +FROM python:3.10-slim +# NOTE: requirements.txt not likely to change between dev builds +COPY requirements.txt . RUN apt-get update && \ apt-get install -y --no-install-recommends \ - build-essential default-libmysqlclient-dev netcat-openbsd vim-tiny jq python3-dev git supervisor curl && \ + build-essential \ + netcat-openbsd \ + vim-tiny \ + jq \ + python3-dev \ + git \ + supervisor \ + curl \ + pkg-config && \ apt-get upgrade -y && \ apt-get clean -y && \ rm -rf /var/lib/apt/lists/* -COPY requirements.txt . +# Install MariaDB from the mariadb repository rather than using Debians +# https://mariadb.com/kb/en/mariadb-package-repository-setup-and-usage/ +RUN curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | bash && \ +apt install -y --no-install-recommends libmariadb-dev + RUN pip install --no-cache-dir -r requirements.txt +RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \ +apt install -y nodejs + WORKDIR /code # Copy only what is needed into /code/ @@ -31,18 +46,21 @@ 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 + -# Collect the static files in the backend -RUN python manage.py collectstatic --verbosity 0 # 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 EXPOSE 5000 -CMD ["/code/start_backend.sh"] +# NOTE: project files likely to change between dev builds +COPY . . -# Done! +CMD ["/usr/bin/supervisord", "-c", "/code/deploy/supervisor_docker.conf"] +# done! \ No newline at end of file diff --git a/docker-compose-openshift-test.yml b/docker-compose-openshift-test.yml deleted file mode 100644 index cfa1ef8..0000000 --- a/docker-compose-openshift-test.yml +++ /dev/null @@ -1,36 +0,0 @@ -version: "3.9" - -services: - - mysql: - image: mysql:5.7 - restart: unless-stopped - command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci'] - environment: - - MYSQL_ROOT_PASSWORD=cae_root_pw - - MYSQL_HOST=canvas_app_explorer_mysql - - MYSQL_PORT=3306 - - MYSQL_DATABASE=canvas_app_explorer_local - - MYSQL_USER=cae_user - - MYSQL_PASSWORD=cae_pw - ports: - - "6306:3306" - volumes: - - ./.data/mysql:/var/lib/mysql:delegated - container_name: canvas_app_explorer_mysql - web: - build: - context: . - dockerfile: dockerfiles/Dockerfile.openshift - args: - - TZ=${TZ} - volumes: - # Only map the secrets for prod build - - ${HOME}/mylasecrets:/secrets - ports: - - "5000:5000" - container_name: canvas_app_explorer_prod - env_file: - - .env - environment: - - DEBUG=False diff --git a/docker-compose.yml b/docker-compose.yml index 1c73a66..e4fcacd 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: diff --git a/dockerfiles/Dockerfile b/dockerfiles/Dockerfile deleted file mode 100644 index bd56d6d..0000000 --- a/dockerfiles/Dockerfile +++ /dev/null @@ -1,48 +0,0 @@ -# FROM directive instructing base image to build upon -# This could be used as a base instead: -# https://hub.docker.com/r/nikolaik/python-nodejs -FROM python:3.10-slim-bookworm - -# NOTE: requirements.txt not likely to change between dev builds -COPY requirements.txt . -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - build-essential \ - default-libmysqlclient-dev \ - netcat-openbsd \ - vim-tiny \ - jq \ - python3-dev \ - git \ - supervisor \ - curl && \ - apt-get upgrade -y && \ - apt-get clean -y && \ - rm -rf /var/lib/apt/lists/* - -RUN pip install --no-cache-dir -r requirements.txt - -WORKDIR /code/frontend - -RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && \ - apt install -y nodejs - -COPY /frontend/package*.json /code/frontend -RUN npm install - -WORKDIR /code - -# 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 -EXPOSE 5000 - -# NOTE: project files likely to change between dev builds -COPY . . - -CMD ["/usr/bin/supervisord", "-c", "/code/deploy/supervisor_docker.conf"] -# done!