Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
backend:
if: "!contains(github.event.pull_request.labels.*.name, 'ops') && !contains(github.head_ref, 'ops/')"
if: ${{ !contains(github.event.pull_request.labels.*.name, 'ops') && !contains(github.head_ref, 'ops/') }}
strategy:
matrix:
node: ["20", "21"]
Expand Down Expand Up @@ -157,7 +157,7 @@ jobs:

frontend:
needs: cache
if: "!contains(github.event.pull_request.labels.*.name, 'ops') && !contains(github.head_ref, 'ops/')"
if: ${{ !contains(github.event.pull_request.labels.*.name, 'ops') && !contains(github.head_ref, 'ops/') }}
strategy:
matrix:
node: ["20", "21"]
Expand Down Expand Up @@ -333,7 +333,7 @@ jobs:
# CYPRESS_PROJECT_ID: ${{ secrets.CYPRESS_PROJECT_ID }}

validate_docker_json:
if: "!contains(github.event.pull_request.labels.*.name, 'ops') && !contains(github.head_ref, 'ops/')"
if: ${{ !contains(github.event.pull_request.labels.*.name, 'ops') && !contains(github.head_ref, 'ops/') }}
runs-on: "ubuntu-latest"
name: Validate generated backend Docker JSON

Expand Down
49 changes: 46 additions & 3 deletions .github/workflows/on-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,22 @@ jobs:
service:
- frontend
- backend
runs-on: [self-hosted, Linux, X64]
runs-on: ${{ github.repository_owner == 'github' && 'ubuntu-latest' || 'self-hosted' }}
timeout-minutes: 120
name: Build and push to DockerHub
steps:
# Workaround based on JonasAlfredsson/docker-on-tmpfs@v1.0.1
- name: Validate runner
run: |
echo "Runner name: ${{ runner.name }}"
echo "Runner OS: ${{ runner.os }}"
if [ -z "${{ runner.name }}" ]; then
echo "Error: Runner not properly initialized"
exit 1
fi

# Only run these steps on GitHub-hosted runners
- name: Replace the current swap file
if: ${{ github.repository_owner == 'github' }}
shell: bash
run: |
sudo swapoff /mnt/swapfile
Expand All @@ -37,13 +47,15 @@ jobs:
sudo swapon /mnt/swapfile

- name: Show current memory and swap status
if: ${{ github.repository_owner == 'github' }}
shell: bash
run: |
sudo free -h
echo
sudo swapon --show

- name: Mount a tmpfs over /var/lib/docker
if: ${{ github.repository_owner == 'github' }}
shell: bash
run: |
if [ ! -d "/var/lib/docker" ]; then
Expand All @@ -54,6 +66,7 @@ jobs:
sudo systemctl restart docker
sudo df -h | grep docker

# Common steps for both environments
- name: Set env variables
run: echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV

Expand All @@ -65,8 +78,25 @@ jobs:
run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV

- name: Login to Docker
timeout-minutes: 5
run: |
docker login -u "sondreb" -p "${{secrets.DOCKER_KEY}}"
max_attempts=3
attempt=1
while [ $attempt -le $max_attempts ]; do
if docker login -u "sondreb" -p "${{secrets.DOCKER_KEY}}"; then
echo "Docker login successful"
break
else
echo "Docker login attempt $attempt failed"
if [ $attempt -eq $max_attempts ]; then
echo "All Docker login attempts failed"
exit 1
fi
sleep 10
((attempt++))
fi
done

- name: Checkout project
uses: actions/checkout@v4

Expand Down Expand Up @@ -94,7 +124,12 @@ jobs:
${{ runner.os }}-buildx-

- name: Run Docker buildx for ${{ matrix.service }} against tag
timeout-minutes: 60
continue-on-error: true
id: docker_build
run: |
set -e
echo "Starting Docker build for ${{ matrix.service }}"
docker buildx build \
--cache-from "type=local,src=/tmp/.buildx-cache" \
--cache-to "type=local,dest=/tmp/.buildx-cache" \
Expand All @@ -105,3 +140,11 @@ jobs:
--build-context backend=./backend \
--output "type=registry" ./${{ matrix.service }}/ \
--build-arg commitHash=$SHORT_SHA

- name: Handle build failure
if: steps.docker_build.outcome == 'failure'
run: |
echo "Docker build failed for ${{ matrix.service }}"
echo "Cleaning Docker cache"
docker builder prune -f
exit 1
Loading