Skip to content

Commit 8dbb9a0

Browse files
authored
Add GitHub workflow to publish containers (#535)
1 parent aa87f8e commit 8dbb9a0

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

.github/workflows/container.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Publish container
2+
on:
3+
push:
4+
branches:
5+
- main
6+
workflow_dispatch:
7+
jobs:
8+
publish-singularity-container:
9+
runs-on: ubuntu-latest
10+
env:
11+
SINGULARITY: 1
12+
steps:
13+
- name: Clone Github Repo Action
14+
uses: actions/checkout@v4
15+
16+
- name: Setup apptainer
17+
uses: eWaterCycle/[email protected]
18+
19+
- name: Get container tag
20+
run: |
21+
TAG=$(cat bin/.container-tag)
22+
echo "TAG=$TAG" >> $GITHUB_ENV
23+
24+
- name: Get container from cache
25+
id: cache-sif
26+
uses: actions/cache@v4
27+
with:
28+
path: .singularity/image.sif
29+
key: ${{ hashFiles('container.def', 'bin/.container-tag') }}
30+
31+
- name: Get gems and node files from cache
32+
id: cache-bundle-npm
33+
uses: actions/cache@v4
34+
with:
35+
path: |
36+
.home/.gems
37+
node_modules
38+
key: ${{ hashFiles('Gemfile.lock') }}-${{ hashFiles('package-lock.json') }}
39+
40+
- if: ${{ steps.cache-sif.outputs.cache-hit != 'true' }}
41+
name: Build container
42+
run: ./bin/build_container
43+
44+
- name: Check if container is already published
45+
run: |
46+
curl --silent -f --head -lL https://hub.docker.com/v2/repositories/riscvintl/spec-generator/tags/${{ env.TAG }}
47+
echo "CURL_EXIT_CODE=$?" >> $GITHUB_ENV
48+
49+
- name: Upload singularity container
50+
if: env.CURL_EXIT_CODE != '0'
51+
run: |
52+
singularity registry login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }}
53+
singularity push .singularity/image-${{ env.TAG }}.img oras://docker.io/riscvintl/spec-generator:${{ env.TAG }}
54+
55+
publish-docker-container:
56+
runs-on: ubuntu-latest
57+
env:
58+
DOCKER: 1
59+
steps:
60+
- name: Get container tag
61+
run: |
62+
TAG=$(cat bin/.container-tag)
63+
echo "TAG=$TAG" >> $GITHUB_ENV
64+
65+
- name: Login to Docker Hub
66+
uses: docker/login-action@v3
67+
with:
68+
username: ${{ secrets.DOCKERHUB_USERNAME }}
69+
password: ${{ secrets.DOCKERHUB_TOKEN }}
70+
71+
- name: Set up QEMU
72+
uses: docker/setup-qemu-action@v3
73+
74+
- name: Set up Docker Buildx
75+
uses: docker/setup-buildx-action@v3
76+
77+
- name: Build and push
78+
uses: docker/build-push-action@v6
79+
with:
80+
push: true
81+
file: ./.devcontainer/Dockerfile
82+
platforms: linux/amd64,linux/arm64
83+
tags: riscvintl/udb:${{ env.TAG }}

0 commit comments

Comments
 (0)