Skip to content

Commit a5989da

Browse files
davezuckermanDavid Zuckerman
andauthored
Adding github actions (#1)
Co-authored-by: David Zuckerman <dzuckerm@library.berkeley.edu>
1 parent d3e9f7d commit a5989da

File tree

5 files changed

+300
-51
lines changed

5 files changed

+300
-51
lines changed

.github/workflows/build.yml

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
name: Build / Test / Push
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
workflow_dispatch:
8+
9+
env:
10+
BUILD_SUFFIX: -build-${{ github.run_id }}_${{ github.run_attempt }}
11+
DOCKER_METADATA_SET_OUTPUT_ENV: 'true'
12+
13+
jobs:
14+
build:
15+
runs-on: ${{ matrix.runner }}
16+
outputs:
17+
image-arm64: ${{ steps.gen-output.outputs.image-arm64 }}
18+
image-x64: ${{ steps.gen-output.outputs.image-x64 }}
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
runner:
23+
- ubuntu-24.04
24+
- ubuntu-24.04-arm
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v4
28+
29+
- name: Set up Docker Buildx
30+
uses: docker/setup-buildx-action@v3
31+
32+
- name: Login to GitHub Container Registry
33+
uses: docker/login-action@v3
34+
with:
35+
registry: ghcr.io
36+
username: ${{ github.actor }}
37+
password: ${{ secrets.GITHUB_TOKEN }}
38+
39+
- id: build-meta
40+
name: Docker meta
41+
uses: docker/metadata-action@v5
42+
with:
43+
images: ghcr.io/${{ github.repository }}
44+
tags: type=sha,suffix=${{ env.BUILD_SUFFIX }}
45+
46+
# Build cache is shared among all builds of the same architecture
47+
- id: cache-meta
48+
name: Docker meta
49+
uses: docker/metadata-action@v5
50+
with:
51+
images: ghcr.io/${{ github.repository }}
52+
tags: type=raw,value=buildcache-${{ runner.arch }}
53+
54+
- id: get-registry
55+
name: Get the sanitized registry name
56+
run: |
57+
echo "registry=$(echo '${{ steps.build-meta.outputs.tags }}' | cut -f1 -d:)" | tee -a "$GITHUB_OUTPUT"
58+
59+
- id: build
60+
name: Build/push the arch-specific image
61+
uses: docker/build-push-action@v6
62+
with:
63+
cache-from: type=registry,ref=${{ steps.cache-meta.outputs.tags }}
64+
cache-to: type=registry,ref=${{ steps.cache-meta.outputs.tags }},mode=max
65+
labels: ${{ steps.build-meta.outputs.labels }}
66+
provenance: mode=max
67+
sbom: true
68+
tags: ${{ steps.get-registry.outputs.registry }}
69+
outputs: type=image,push-by-digest=true,push=true
70+
71+
- id: gen-output
72+
name: Write arch-specific image digest to outputs
73+
run: |
74+
echo "image-${RUNNER_ARCH,,}=${{ steps.get-registry.outputs.registry }}@${{ steps.build.outputs.digest }}" | tee -a "$GITHUB_OUTPUT"
75+
76+
merge:
77+
runs-on: ubuntu-24.04
78+
needs: build
79+
env:
80+
DOCKER_APP_IMAGE_ARM64: ${{ needs.build.outputs.image-arm64 }}
81+
DOCKER_APP_IMAGE_X64: ${{ needs.build.outputs.image-x64 }}
82+
outputs:
83+
image: ${{ steps.meta.outputs.tags }}
84+
steps:
85+
- name: Checkout code
86+
uses: actions/checkout@v4
87+
88+
- name: Set up Docker Buildx
89+
uses: docker/setup-buildx-action@v3
90+
91+
- name: Login to GitHub Container Registry
92+
uses: docker/login-action@v3
93+
with:
94+
registry: ghcr.io
95+
username: ${{ github.actor }}
96+
password: ${{ secrets.GITHUB_TOKEN }}
97+
98+
- id: meta
99+
name: Generate tag for the app image
100+
uses: docker/metadata-action@v5
101+
with:
102+
images: ghcr.io/${{ github.repository }}
103+
tags: type=sha,suffix=${{ env.BUILD_SUFFIX }}
104+
105+
- name: Push the multi-platform app image
106+
run: |
107+
docker buildx imagetools create \
108+
--tag "$DOCKER_METADATA_OUTPUT_TAGS" \
109+
"$DOCKER_APP_IMAGE_ARM64" "$DOCKER_APP_IMAGE_X64"
110+
111+
test:
112+
runs-on: ubuntu-24.04
113+
needs: merge
114+
env:
115+
COMPOSE_FILE: docker-compose.yml:docker-compose.ci.yml
116+
DOCKER_APP_IMAGE: ${{ needs.merge.outputs.image }}
117+
steps:
118+
- name: Checkout code
119+
uses: actions/checkout@v4
120+
121+
- name: Set up Docker Compose
122+
uses: docker/setup-compose-action@v1
123+
124+
- name: Login to GitHub Container Registry
125+
uses: docker/login-action@v3
126+
with:
127+
registry: ghcr.io
128+
username: ${{ github.actor }}
129+
password: ${{ secrets.GITHUB_TOKEN }}
130+
131+
- name: Setup the stack
132+
run: |
133+
docker compose build --quiet
134+
docker compose pull --quiet
135+
docker compose up --wait
136+
docker compose exec -e RAILS_ENV=test app rails db:await db:setup assets:precompile
137+
docker compose exec -u root app chown -R altmedia:altmedia artifacts
138+
139+
- name: Run RSpec
140+
if: ${{ always() }}
141+
run: |
142+
docker compose exec -e RAILS_ENV=test app rake coverage
143+
# docker compose exec -e RAILS_ENV=test app rake check
144+
# docker compose exec -e RAILS_ENV=test app rspec --format progress --format html --out artifacts/rspec.html
145+
146+
- name: Run Rubocop
147+
if: ${{ always() }}
148+
run: |
149+
docker compose exec -e RAILS_ENV=test app rake rubocop
150+
151+
- name: Run Brakeman
152+
if: ${{ always() }}
153+
run: |
154+
docker compose exec -e RAILS_ENV=test app rake brakeman
155+
156+
- name: Run ESLint
157+
if: ${{ always() }}
158+
run: |
159+
docker compose exec -e RAILS_ENV=test app rake bundle:audit
160+
161+
- name: Copy out artifacts
162+
if: ${{ always() }}
163+
run: |
164+
docker compose cp app:/opt/app/artifacts ./
165+
docker compose logs > artifacts/docker-compose-services.log
166+
docker compose config > artifacts/docker-compose.merged.yml
167+
168+
- name: Upload the test report
169+
if: ${{ always() }}
170+
uses: actions/upload-artifact@v4
171+
with:
172+
name: Framework Build Report (${{ github.run_id }}_${{ github.run_attempt }})
173+
path: artifacts/*
174+
if-no-files-found: error
175+
176+
push:
177+
runs-on: ubuntu-24.04
178+
needs:
179+
- merge
180+
- test
181+
env:
182+
DOCKER_APP_IMAGE: ${{ needs.merge.outputs.image }}
183+
steps:
184+
- name: Checkout code
185+
uses: actions/checkout@v4
186+
187+
- name: Login to GitHub Container Registry
188+
uses: docker/login-action@v3
189+
with:
190+
registry: ghcr.io
191+
username: ${{ github.actor }}
192+
password: ${{ secrets.GITHUB_TOKEN }}
193+
194+
- name: Produce permanent image tags
195+
uses: docker/metadata-action@v5
196+
with:
197+
images: ghcr.io/${{ github.repository }}
198+
tags: |
199+
type=sha
200+
type=ref,event=branch
201+
type=raw,value=latest,enable={{is_default_branch}}
202+
203+
- name: Retag and push the image
204+
run: |
205+
docker pull "$DOCKER_APP_IMAGE"
206+
echo "$DOCKER_METADATA_OUTPUT_TAGS" | tr ' ' '\n' | xargs -n1 docker tag "$DOCKER_APP_IMAGE"
207+
docker push --all-tags "$(echo "$DOCKER_APP_IMAGE" | cut -f1 -d:)"

.github/workflows/release.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Push Release Tags
2+
3+
on:
4+
push:
5+
tags:
6+
- '**'
7+
workflow_dispatch:
8+
9+
env:
10+
DOCKER_METADATA_SET_OUTPUT_ENV: 'true'
11+
12+
jobs:
13+
retag:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Docker Buildx
20+
uses: docker/setup-buildx-action@v3
21+
22+
- name: Login to GitHub Container Registry
23+
uses: docker/login-action@v3
24+
with:
25+
registry: ghcr.io
26+
username: ${{ github.actor }}
27+
password: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: Determine the sha-based image tag to retag
30+
id: get-base-image
31+
uses: docker/metadata-action@v5
32+
with:
33+
images: ghcr.io/${{ github.repository }}
34+
tags: type=sha
35+
36+
- name: Verify that the image was previously built
37+
env:
38+
BASE_IMAGE: ${{ steps.get-base-image.outputs.tags }}
39+
run: |
40+
docker pull "$BASE_IMAGE"
41+
42+
- name: Produce release tags
43+
id: tag-meta
44+
uses: docker/metadata-action@v5
45+
with:
46+
images: ghcr.io/${{ github.repository }}
47+
flavor: latest=false
48+
tags: |
49+
type=ref,event=tag
50+
type=semver,pattern={{major}}
51+
type=semver,pattern={{major}}.{{minor}}
52+
type=semver,pattern={{version}}
53+
54+
- name: Retag the pulled image
55+
env:
56+
BASE_IMAGE: ${{ steps.get-base-image.outputs.tags }}
57+
run: |
58+
echo "$DOCKER_METADATA_OUTPUT_TAGS" | tr ' ' '\n' | xargs -n1 docker tag "$BASE_IMAGE"
59+
docker push --all-tags "$(echo "$BASE_IMAGE" | cut -f1 -d:)"

Jenkinsfile

Lines changed: 0 additions & 22 deletions
This file was deleted.

docker-compose.ci.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
services:
2+
db:
3+
volumes: !reset
4+
5+
app:
6+
build: !reset
7+
environment:
8+
- CAPYBARA_SAVE_PATH=/opt/app/artifacts
9+
image: ${DOCKER_APP_IMAGE}
10+
depends_on:
11+
- selenium
12+
volumes: !override
13+
- artifacts:/opt/app/artifacts
14+
ports: !reset
15+
16+
worker:
17+
build: !reset
18+
image: ${DOCKER_APP_IMAGE}
19+
volumes: !reset
20+
21+
selenium:
22+
volumes: !override
23+
- artifacts:/build
24+
25+
dbeaver: !reset
26+
27+
volumes:
28+
artifacts:

docker-compose.yml

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ services:
1010
condition: service_started
1111
selenium:
1212
condition: service_started
13-
selenium-chrome:
14-
condition: service_started
1513
init: true
1614
networks:
1715
default:
@@ -29,7 +27,6 @@ services:
2927
depends_on:
3028
- db
3129
- selenium
32-
- selenium-chrome
3330
ports: []
3431

3532
db:
@@ -48,45 +45,25 @@ services:
4845
- ./:/build:rw
4946

5047
selenium:
51-
image: selenium/hub
52-
# image: selenium/hub:4.10.0
48+
image: selenium/standalone-chromium
5349
networks:
5450
default:
5551
aliases:
5652
- selenium.test
5753
ports:
58-
- 4442:4442
59-
- 4443:4443
6054
- 4444:4444
55+
- 7900:7900
56+
shm_size: 2gb
6157
volumes:
6258
- ./:/build:rw
6359

64-
selenium-chrome:
65-
image: selenium/node-chromium
66-
# image: selenium/node-chrome:4.10.0
67-
# shm_size: 2gb
68-
depends_on:
69-
- selenium
70-
environment:
71-
- SE_EVENT_BUS_HOST=selenium
72-
- SE_EVENT_BUS_PUBLISH_PORT=4442
73-
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
74-
ports:
75-
# @note Use `open vnc://localhost:55900` to view the chrome session.
76-
# Doesn't work if you pass the "headless" option via Capybara.
77-
# Password = "secret"
78-
- 55900:5900
79-
volumes:
80-
- /dev/shm:/dev/shm:rw
81-
- ./:/build:rw
82-
8360
dbeaver:
8461
image: dbeaver/cloudbeaver:latest
85-
container_name: dbeaver
62+
container_name: dbeaver
8663
depends_on:
8764
- db
8865
restart: always
8966
ports:
9067
- '8080:8978'
91-
volumes:
92-
- ./:/build:rw
68+
volumes:
69+
- ./:/build:rw

0 commit comments

Comments
 (0)