Skip to content

Commit

Permalink
tl-its-umich-edu#322 Adding GH action workflow and keeping one docker…
Browse files Browse the repository at this point in the history
…file
  • Loading branch information
pushyamig committed Nov 25, 2024
1 parent 13d56fb commit 2f51bb0
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 11 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/build_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
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
- 'issue_322'
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 }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ venv/
ENV/
env.bak/
venv.bak/
venv_*

# Spyder project settings
.spyderproject
Expand Down Expand Up @@ -261,6 +262,7 @@ dist

# Stores VSCode versions used for testing VSCode extensions
.vscode-test
.history

# yarn v2
.yarn/cache
Expand Down
32 changes: 23 additions & 9 deletions dockerfiles/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion deploy/supervisor_docker.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ services:
web:
build:
context: .
dockerfile: dockerfiles/Dockerfile
dockerfile: Dockerfile
args:
TZ: ${TZ}
volumes:
Expand All @@ -35,6 +35,7 @@ services:
- .env
environment:
- DEBUG=True
- RUN_FRONTEND=true
redis:
image: redis:7
volumes:
Expand Down

0 comments on commit 2f51bb0

Please sign in to comment.