Skip to content

Commit 3f0ec07

Browse files
davezuckermanDavid Zuckerman
andauthored
adding actions (#2)
fixed deprecation issues with Docker removed reference to containers.lib image in docker-compose reset secrets in compose.ci moved COA user to environment removing tests for now. will need to be reworked removing tests for now. will need to be reworked updated read me and sftp user moving username to environement variable remove environment for tests, adding tests to build.yml renamed bfs service to app in docker compose Adding /opt/app directory and add artifacts to .gitignore referencing /opt/app as oppose to /opt/app-root/src as base directory adding file processing test removed path for image in container.lib skipping sftp for tests fixed typo for override in compose.ci syntax error in compose.ci build report was named Gobi instead of BFS using newer build and release template, slight syntax change in compose.ci reverting compose.ci to debug DOCKER_APP_IMAGE incorrectly mapped changed compose.ci to use array syntax Co-authored-by: David Zuckerman <dzuckerm@library.berkeley.edu>
1 parent 142c954 commit 3f0ec07

File tree

11 files changed

+315
-28
lines changed

11 files changed

+315
-28
lines changed

.github/workflows/build.yml

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

.github/workflows/release.yml

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

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ data/invoicing/pay/processed/*
2020

2121
ssh_tests
2222

23+
# Build/test artifacts
24+
artifacts/*
25+
2326
vendor
2427
.bundle
2528

.ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.1.2
1+
3.1.7

Dockerfile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
FROM registry.access.redhat.com/ubi8/ruby-31
2-
32
USER root
43

54
# Configure users and groups
65
RUN groupadd -g 40054 alma && \
76
useradd -r -s /sbin/nologin -M -u 40054 -g alma alma && \
87
groupadd -g 40061 bfs && \
98
usermod -u 40061 -g bfs -G alma -l bfs default && \
10-
find / -user 1001 -exec chown -h bfs {} \; || true
9+
find / -user 1001 -exec chown -h bfs {} \; || true && \
10+
mkdir -p /opt/app && \
11+
chown -R bfs:bfs /opt/app
1112

13+
WORKDIR /opt/app
1214
COPY --chown=bfs Gemfile* .ruby-version ./
13-
RUN bundle install --system
15+
RUN bundle config set force_ruby_platform true
16+
RUN bundle config set system 'true'
17+
RUN bundle install
1418
COPY --chown=bfs . .
1519

1620
USER bfs
17-
ENTRYPOINT ["/opt/app-root/src/bin/bfs"]
21+
ENTRYPOINT ["/opt/app/bin/bfs"]
1822
CMD ["help"]

Jenkinsfile

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,46 @@ A command-line tool for processing BFS .xml files. Input files can be mounted an
55
## Building the app
66

77
```sh
8-
docker-compose build
8+
docker compose build
99
```
1010

1111
## Running it
1212

1313
View the CLI tool help/description:
1414

1515
```sh
16-
docker-compose run --rm bfs help
16+
docker compose run --rm bfs help
1717
```
1818

1919
Adds test data to the default watch directory:
2020

2121
```sh
22-
docker-compose run --rm bfs seed
22+
docker compose run --rm bfs seed
2323
```
2424

2525
Run the app in the background. It will continue running, monitoring for .xml files to process every 10s.
2626

2727
```sh
28-
docker-compose up -d
29-
docker-compose logs -f # view processing logs in real time
28+
docker compose up -d
29+
docker compose logs -f # view processing logs in real time
3030
```
3131

3232
Watch a non-standard directory:
3333

3434
```sh
35-
docker-compose run --rm bfs watch /path/in/container # absolute path
36-
docker-compose run --rm bfs watch data/somedir # path relative to /opt/app-root/src
35+
docker compose run --rm bfs watch /path/in/container # absolute path
36+
docker compose run --rm bfs watch data/somedir # path relative to /opt/app-root/src
3737
```
3838

3939
Process a specific file:
4040

4141
```sh
42-
docker-compose run --rm bfs process /abs/path/to/myfile.xml # absolute path
43-
docker-compose run --rm bfs process data/invoicing/pay/somefile.xml # relative path
42+
docker compose run --rm bfs process /abs/path/to/myfile.xml # absolute path
43+
docker compose run --rm bfs process data/invoicing/pay/somefile.xml # relative path
4444
```
4545

4646
Delete previously processed files and error logs:
4747

4848
```sh
49-
docker-compose run --rm bfs clear
49+
docker compose run --rm bfs clear
5050
```

docker-compose.ci.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
services:
2+
app:
3+
build: !reset
4+
image: ${DOCKER_APP_IMAGE}
5+
environment: !override
6+
- SKIP_SFTP=skip_sftp
7+
volumes: !override
8+
- artifacts:/opt/app/artifacts
9+
secrets: !reset
10+
11+
volumes:
12+
artifacts:
13+
14+
secrets: !reset

0 commit comments

Comments
 (0)