diff --git a/.github/actions/build/action.yaml b/.github/actions/build/action.yaml new file mode 100644 index 00000000..a41a335e --- /dev/null +++ b/.github/actions/build/action.yaml @@ -0,0 +1,83 @@ +name: 'Build Image' +description: 'Builds and pushes images' +inputs: + image-tag-prefix: # prefix the tag with this + description: 'IMAGE_TAG_PREFIX' + required: false + default: '' + backend-dockerfile: # dockerfile for backend build + description: 'DOCKERFILE_BACKEND' + required: false + default: Dockerfile.backend-container + frontend-dockerfile: # dockerfile for frontend build + description: 'DOCKERFILE_FRONTEND' + required: false + default: frontend/Dockerfile.frontend-container + tag-version: # set to true if tagging official version + description: 'VERSION' + required: false + default: false +runs: + using: "composite" + steps: + - name: Set image tag prefix + shell: bash + run: echo "IMAGE_TAG_PREFIX=${{ inputs.image-tag-prefix }}" >> $GITHUB_ENV + - name: Set backend dockerfile + shell: bash + run: echo "DOCKERFILE_BACKEND=${{ inputs.backend-dockerfile }}" >> $GITHUB_ENV + - name: Set frontend dockerfile + shell: bash + run: echo "DOCKERFILE_FRONTEND=${{ inputs.frontend-dockerfile }}" >> $GITHUB_ENV + + - name: Install Golang + uses: actions/setup-go@v5.0.0 + with: + go-version-file: go.mod + check-latest: true + cache: true + + - name: Download modules + shell: bash + run: go mod download + + - uses: actions/setup-node@v4.0.2 + with: + node-version: '18' + + # https://github.com/docker/setup-qemu-action + #- name: Set up QEMU + # uses: docker/setup-qemu-action@v3 + # https://github.com/docker/setup-buildx-action + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Download modules + shell: bash + run: go mod download + + - name: golangci-lint + uses: golangci/golangci-lint-action@v4.0.0 + with: + version: v1.53 + args: --timeout 7m + + # set repo and GITHUB SHA + - name: Set github commit id + shell: bash + run: echo "GITHUB_SHA=$GITHUB_SHA" >> $GITHUB_ENV + - name: Set release repo + shell: bash + run: echo "REPO=ghcr.io/${{ github.repository_owner }}" >> $GITHUB_ENV + # override version with GITHUB_SHA if tag-version set to false + # this way only GITHUBSHA is tagged with this build + - name: Override version if not official build + shell: bash + if: ${{ inputs.tag-version == 'false' }} + run: echo "VERSION=$GITHUB_SHA" >> $GITHUB_ENV + + # build and push images tagged with GITHUB_SHA, version + - name: Build and push tornjak images + shell: bash + run: make release-images + diff --git a/.github/workflows/master-build.yaml b/.github/workflows/master-build.yaml index 38833b7b..4c700bda 100644 --- a/.github/workflows/master-build.yaml +++ b/.github/workflows/master-build.yaml @@ -1,11 +1,9 @@ name: Tornjak Artifact push on: - push: - branches: - - main - - v1.6 + push: {} + workflow_dispatch: {} jobs: - tornjak-build: + alpine-build: runs-on: ubuntu-latest steps: - name: Show trigger info @@ -20,65 +18,60 @@ jobs: - name: Check out repository code uses: actions/checkout@v4.1.2 - - - name: Install Golang - uses: actions/setup-go@v5.0.0 + - name: Log in to GHCR.io + uses: docker/login-action@v3.1.0 with: - go-version-file: go.mod - check-latest: true - cache: true + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} - - name: Download modules - run: go mod download + - name: Get branch name + id: branch_name + run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" - - uses: actions/setup-node@v4.0.2 + - name: Run build + uses: ./.github/actions/build with: - node-version: '18' + tag-version: ${{ contains(fromJSON('["main", "v1.6"]'), steps.branch_name.outputs.branch) && true || false }} - # https://github.com/docker/setup-qemu-action - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - # https://github.com/docker/setup-buildx-action - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Download modules - run: go mod download + - name: Print job result + run: | + cat <>"${GITHUB_STEP_SUMMARY}" + - 🍏 This job's status is ${{ job.status }}. + EOF + ubi-build: + runs-on: ubuntu-latest + steps: + - name: Show trigger info + run: | + cat <>"${GITHUB_STEP_SUMMARY}" + # Workflow job info - - name: golangci-lint - uses: golangci/golangci-lint-action@v4.0.0 - with: - version: v1.53 - args: --timeout 7m + - 🎉 The job was automatically triggered by a ${{ github.event_name }} event. + - 🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub! + - 🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}. + EOF + - name: Check out repository code + uses: actions/checkout@v4.1.2 - name: Log in to GHCR.io uses: docker/login-action@v3.1.0 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - - # set repo and GITHUB SHA - - name: Set github commit id - run: echo "GITHUB_SHA=$GITHUB_SHA" >> $GITHUB_ENV - - - name: Set release repo - run: echo "REPO=ghcr.io/${{ github.repository_owner }}" >> $GITHUB_ENV - - # build and push images tagged with GITHUB_SHA, version - - name: Build and push tornjak images - run: make release-images - # build and push UBI images - - name: Add ubi prefix - run: echo "IMAGE_TAG_PREFIX=ubi-" >> $GITHUB_ENV - - name: Set frontend Dockerfile - run: echo "DOCKERFILE_FRONTEND=frontend/Dockerfile.frontend-container.ubi" >> $GITHUB_ENV - - name: Set backend Dockerfile - run: echo "DOCKERFILE_BACKEND=Dockerfile.backend-container.ubi" >> $GITHUB_ENV + - name: Get branch name + id: branch_name + run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" - - name: Build and push UBI images - run: make release-images + - name: Run build + uses: ./.github/actions/build + with: + image-tag-prefix: ubi- + backend-dockerfile: Dockerfile.backend-container.ubi + frontend-dockerfile: frontend/Dockerfile.frontend-container.ubi + tag-version: ${{ contains(fromJSON('["main", "v1.6"]'), steps.branch_name.outputs.branch) && true || false }} - name: Print job result run: | diff --git a/Makefile b/Makefile index c4d308c5..ac5bba72 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION=$(shell cat version.txt) +VERSION ?= $(shell cat version.txt) GITHUB_SHA ?= "$(shell git rev-parse HEAD 2>/dev/null)" ## REPO defines where to push images diff --git a/frontend/Dockerfile.frontend-container.ubi b/frontend/Dockerfile.frontend-container.ubi index 7caa1438..5322b22b 100644 --- a/frontend/Dockerfile.frontend-container.ubi +++ b/frontend/Dockerfile.frontend-container.ubi @@ -1,15 +1,14 @@ -## Build stage -FROM registry.access.redhat.com/ubi9/nodejs-18:latest AS build -WORKDIR /opt/app-root/src -COPY --chown=1001:0 frontend . +FROM node:18-alpine3.14 AS build +WORKDIR /usr/src/app +COPY frontend . RUN npm install && \ npm run build ## Runtime stage FROM registry.access.redhat.com/ubi9/nodejs-18-minimal:latest AS runtime WORKDIR /opt/app-root/src -COPY --from=build --chown=1001:0 /opt/app-root/src/build ./build -COPY --from=build --chown=1001:0 /opt/app-root/src/.env.prod . +COPY --from=build --chown=1001:0 /usr/src/app/build ./build +COPY --from=build --chown=1001:0 /usr/src/app/.env.prod . # Install serve package and react-inject-env RUN npm install -g npm@9.7.1 && \