Skip to content

Commit 463b219

Browse files
authored
Fix docker build (#34)
* Update on-tag.yml * Refactor GitHub Actions workflow to improve runner configuration and error handling
1 parent 47f30d0 commit 463b219

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

.github/workflows/on-tag.yml

+26-17
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,40 @@ jobs:
2121
service:
2222
- frontend
2323
- backend
24-
# Add fail-fast configuration
24+
runner-label:
25+
- ubuntu-latest
26+
- self-hosted
2527
fail-fast: false
26-
runs-on: ${{ github.event.repository.has_issues && 'ubuntu-latest' || 'self-hosted' }}
28+
runs-on: ${{ matrix.runner-label }}
29+
continue-on-error: ${{ matrix.runner-label == 'self-hosted' }}
2730
timeout-minutes: 120
28-
name: Build and push to DockerHub
29-
# Add concurrency group to prevent multiple runs
31+
name: Build ${{ matrix.service }} on ${{ matrix.runner-label }}
3032
concurrency:
31-
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.service }}
33+
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.service }}-${{ matrix.runner-label }}
3234
cancel-in-progress: true
35+
3336
steps:
34-
# Workaround based on JonasAlfredsson/[email protected]
35-
- name: Replace the current swap file
37+
- name: Runner check
38+
id: runner-check
39+
run: |
40+
echo "Running on ${{ matrix.runner-label }}"
41+
if [ "${{ matrix.runner-label }}" = "self-hosted" ]; then
42+
echo "Using self-hosted runner"
43+
else
44+
echo "Using GitHub-hosted runner"
45+
fi
46+
47+
# Skip swap configuration for GitHub-hosted runners
48+
- name: Configure swap
49+
if: matrix.runner-label == 'self-hosted'
3650
shell: bash
3751
run: |
38-
sudo swapoff /mnt/swapfile
39-
sudo rm -v /mnt/swapfile
40-
sudo fallocate -l 13G /mnt/swapfile
52+
sudo swapoff /mnt/swapfile || true
53+
sudo rm -f /mnt/swapfile || true
54+
sudo fallocate -l 13G /mnt/swapfile || true
4155
sudo chmod 600 /mnt/swapfile
4256
sudo mkswap /mnt/swapfile
43-
sudo swapon /mnt/swapfile
57+
sudo swapon /mnt/swapfile || true
4458
4559
- name: Show current memory and swap status
4660
shell: bash
@@ -50,6 +64,7 @@ jobs:
5064
sudo swapon --show
5165
5266
- name: Mount a tmpfs over /var/lib/docker
67+
if: matrix.runner-label == 'self-hosted'
5368
shell: bash
5469
run: |
5570
if [ ! -d "/var/lib/docker" ]; then
@@ -60,7 +75,6 @@ jobs:
6075
sudo systemctl restart docker
6176
sudo df -h | grep docker
6277
63-
# Add caching for Cargo registry
6478
- name: Cache Cargo registry
6579
uses: actions/cache@v3
6680
with:
@@ -69,7 +83,6 @@ jobs:
6983
restore-keys: |
7084
${{ runner.os }}-cargo-registry-
7185
72-
# Add caching for Cargo index
7386
- name: Cache Cargo index
7487
uses: actions/cache@v3
7588
with:
@@ -78,7 +91,6 @@ jobs:
7891
restore-keys: |
7992
${{ runner.os }}-cargo-index-
8093
81-
# Add caching for Cargo build
8294
- name: Cache Cargo build
8395
uses: actions/cache@v3
8496
with:
@@ -97,9 +109,6 @@ jobs:
97109
- name: Add SHORT_SHA env property with commit short sha
98110
run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV
99111

100-
# - name: Login to Docker for building
101-
# run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
102-
103112
- name: Login to Docker
104113
run: |
105114
docker login -u "sondreb" -p "${{secrets.DOCKER_KEY}}"

0 commit comments

Comments
 (0)