diff --git a/.github/workflows/ccm.yml b/.github/workflows/ccm.yml new file mode 100644 index 00000000..de334f73 --- /dev/null +++ b/.github/workflows/ccm.yml @@ -0,0 +1,67 @@ +name: CCM 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 == 'tl-its-umich-edu' + 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: | + cd ccm_web + docker build . --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/') && github.repository_owner == 'tl-its-umich-edu' + 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@v1 + with: + draft: true + prerelease: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + \ No newline at end of file diff --git a/README.md b/README.md index 1bef6890..4fdd1dbc 100644 --- a/README.md +++ b/README.md @@ -346,3 +346,15 @@ This repository contains modified portions of the npm package [@types/ltijs](https://www.npmjs.com/package/@types/ltijs), which carries an MIT license. See `ccm_web/server/localTypes/ltijs/index.d.ts` for more information and the modified code. This code will hopefully only remain in this repository temporarily. + +## GitHub Action +1. The [GitHub action](https://docs.github.com/en/actions/quickstart) configuration in [/.github/workflows/ccm.yml](../.github/workflows/ccm.yml) uses Dockerfile to build the app, then pushes the image to the [GitHub container registry (GHCR)](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry). +2. The action is triggered whenever a commit is made to the `main` branch. E.g., when a pull request is merged to `main`. +3. OpenShift projects can periodically pull this image from GHCR. Configure only **_NON-PRODUCTION_** CCM projects to pull the imageā€¦ + ```sh + oc tag ghcr.io/tl-its-umich-edu/canvas-course-manager-next:latest canvas-course-manager-next:latest --scheduled --reference-policy=local + ``` + See the OpenShift documentation "[Managing image streams: Configuring periodic importing of image stream tags](https://docs.openshift.com/container-platform/4.11/openshift_images/image-streams-manage.html#images-imagestream-import_image-streams-managing)" for details. + + `reference-policy=local` : If you want to instruct OpenShift Container Platform to always fetch the tagged image from the [integrated registry](https://docs.openshift.com/container-platform/4.11/openshift_images/managing_images/tagging-images.html#images-add-tags-to-imagestreams_tagging-images) + diff --git a/ccm_web/Dockerfile.openshift b/ccm_web/Dockerfile.openshift deleted file mode 100644 index bdaa901f..00000000 --- a/ccm_web/Dockerfile.openshift +++ /dev/null @@ -1,32 +0,0 @@ -# Build stage (build client and compile server to JS) -FROM docker-registry.default.svc:5000/openshift/node:16-slim AS build -WORKDIR /build/ - -COPY package*.json ./ -RUN npm install - -COPY . . -RUN npm run build - -# Prod stage -FROM docker-registry.default.svc:5000/openshift/node:16-slim AS prod -ENV NODE_ENV=production -WORKDIR /app - -COPY --from=build \ - /build/package.json \ - /build/package-lock.json \ - /build/start.sh \ - /build/ecosystem.config.js \ - ./ -RUN npm install --production -RUN npm install pm2@5.2.0 -g -COPY --from=build /build/dist/ ./ - -# Set PM2_HOME so that .pm2 files are written in /tmp/ -ENV PM2_HOME=/tmp/.pm2 -ARG PORT -EXPOSE ${PORT} -ENTRYPOINT ["./start.sh"] - -# Done!