From e707875e826fb5a01a29ff321f29adb2011cf9a8 Mon Sep 17 00:00:00 2001 From: Oscar Eriksson Date: Sun, 5 Nov 2023 20:30:40 +0100 Subject: [PATCH 1/4] Make docker build Requires Node 16 but current LTS is 18 --- backend/Dockerfile | 4 ++-- frontend/Dockerfile | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index 89c6d3c..e848c85 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,4 +1,4 @@ -FROM node:lts as build +FROM node:16 as build COPY package.json package-lock.json ./ COPY ./prisma/ . @@ -7,7 +7,7 @@ RUN npm install COPY . . RUN npm run build -FROM node:lts +FROM node:16 COPY --from=build ./build ./build/ COPY --from=build ./src/schemas ./build/schemas diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 99b5150..55dc48e 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,4 +1,4 @@ -FROM node:lts as build +FROM node:16 as build COPY package.json package-lock.json ./ From e6b8827ef63cf27e3fbc3bda5c3b31c8ad09fe80 Mon Sep 17 00:00:00 2001 From: Oscar Eriksson Date: Sun, 5 Nov 2023 20:33:31 +0100 Subject: [PATCH 2/4] Add workflows for ghcr build --- .github/workflows/backend.yml | 46 ++++++++++++++++++++++++++++++++++ .github/workflows/frontend.yml | 46 ++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 .github/workflows/backend.yml create mode 100644 .github/workflows/frontend.yml diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml new file mode 100644 index 0000000..a26abce --- /dev/null +++ b/.github/workflows/backend.yml @@ -0,0 +1,46 @@ +on: [push, pull_request] + +name: "Backend CI" + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: 16 + - name: Install dependencies + run: npm install + working-directory: backend + - name: Build + run: npm run build + working-directory: backend + + docker: + runs-on: ubuntu-latest + needs: + - build + permissions: + packages: write + steps: + - uses: actions/checkout@v3 + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v2 + - name: Login to GitHub Container Registry + if: ${{ github.ref == 'refs/heads/main' }} + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + context: ./backend + file: ./backend/Dockerfile + push: ${{ github.ref == 'refs/heads/main' }} + tags: ghcr.io/cthit/bookIT-node-backend:latest diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml new file mode 100644 index 0000000..e8ca629 --- /dev/null +++ b/.github/workflows/frontend.yml @@ -0,0 +1,46 @@ +on: [push, pull_request] + +name: "Frontend CI" + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: 16 + - name: Install dependencies + run: npm install + working-directory: frontend + - name: Build + run: npm run build + working-directory: frontend + + docker: + runs-on: ubuntu-latest + needs: + - build + permissions: + packages: write + steps: + - uses: actions/checkout@v3 + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v2 + - name: Login to GitHub Container Registry + if: ${{ github.ref == 'refs/heads/main' }} + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + context: ./frontend + file: ./frontend/Dockerfile + push: ${{ github.ref == 'refs/heads/main' }} + tags: ghcr.io/cthit/bookIT-node-frontend:latest From 8373875988cabdf8c8bb10e158f71eeff57be56a Mon Sep 17 00:00:00 2001 From: Oscar Eriksson Date: Sun, 5 Nov 2023 20:40:55 +0100 Subject: [PATCH 3/4] Make docker tag lowercase --- .github/workflows/backend.yml | 2 +- .github/workflows/frontend.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index a26abce..ffaa00c 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -43,4 +43,4 @@ jobs: context: ./backend file: ./backend/Dockerfile push: ${{ github.ref == 'refs/heads/main' }} - tags: ghcr.io/cthit/bookIT-node-backend:latest + tags: ghcr.io/cthit/bookit-node-backend:latest diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index e8ca629..d667277 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -43,4 +43,4 @@ jobs: context: ./frontend file: ./frontend/Dockerfile push: ${{ github.ref == 'refs/heads/main' }} - tags: ghcr.io/cthit/bookIT-node-frontend:latest + tags: ghcr.io/cthit/bookit-node-frontend:latest From d08e6696f46e4ce8b27ab878eb7a5c9a2325043e Mon Sep 17 00:00:00 2001 From: Oscar Eriksson Date: Sun, 5 Nov 2023 20:45:37 +0100 Subject: [PATCH 4/4] Specify more when workflows should be run --- .github/workflows/backend.yml | 6 +++++- .github/workflows/frontend.yml | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index ffaa00c..92ed9f3 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -1,4 +1,8 @@ -on: [push, pull_request] +on: + push: + branches: [main] + pull_request: + branches: [main] name: "Backend CI" diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index d667277..2b5dcdd 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -1,4 +1,8 @@ -on: [push, pull_request] +on: + push: + branches: [main] + pull_request: + branches: [main] name: "Frontend CI"