Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split Master Build into two jobs (#378) #382

Merged
merged 15 commits into from
Mar 28, 2024
83 changes: 83 additions & 0 deletions .github/actions/build/action.yaml
Original file line number Diff line number Diff line change
@@ -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

91 changes: 42 additions & 49 deletions .github/workflows/master-build.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 <<EOF >>"${GITHUB_STEP_SUMMARY}"
- 🍏 This job's status is ${{ job.status }}.
EOF
ubi-build:
runs-on: ubuntu-latest
steps:
- name: Show trigger info
run: |
cat <<EOF >>"${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: |
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 5 additions & 6 deletions frontend/Dockerfile.frontend-container.ubi
Original file line number Diff line number Diff line change
@@ -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 && \
Expand Down
Loading