Skip to content

Commit f1f831a

Browse files
author
David Zuckerman
committed
adding actions
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
1 parent 142c954 commit f1f831a

11 files changed

Lines changed: 289 additions & 28 deletions

File tree

.github/workflows/build.yml

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
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 -u root app chown -R bfs:bfs artifacts
137+
138+
- name: Run RSpec
139+
if: ${{ always() }}
140+
run: |
141+
docker compose exec -e RAILS_ENV=test app rspec --format progress --format html --out artifacts/rspec.html
142+
143+
- name: Copy out artifacts
144+
if: ${{ always() }}
145+
run: |
146+
docker compose cp app:/opt/app/artifacts ./
147+
docker compose logs > artifacts/docker-compose-services.log
148+
docker compose config > artifacts/docker-compose.merged.yml
149+
150+
- name: Upload the test report
151+
if: ${{ always() }}
152+
uses: actions/upload-artifact@v4
153+
with:
154+
name: BFS Build Report (${{ github.run_id }}_${{ github.run_attempt }})
155+
path: artifacts/*
156+
if-no-files-found: error
157+
158+
push:
159+
runs-on: ubuntu-24.04
160+
needs:
161+
- merge
162+
# - test
163+
env:
164+
DOCKER_APP_IMAGE: ${{ needs.merge.outputs.image }}
165+
steps:
166+
- name: Checkout code
167+
uses: actions/checkout@v4
168+
169+
- name: Login to GitHub Container Registry
170+
uses: docker/login-action@v3
171+
with:
172+
registry: ghcr.io
173+
username: ${{ github.actor }}
174+
password: ${{ secrets.GITHUB_TOKEN }}
175+
176+
- name: Produce permanent image tags
177+
uses: docker/metadata-action@v5
178+
with:
179+
images: ghcr.io/${{ github.repository }}
180+
tags: |
181+
type=sha
182+
type=ref,event=branch
183+
type=raw,value=latest,enable={{is_default_branch}}
184+
185+
- name: Retag and push the image
186+
run: |
187+
docker pull "$DOCKER_APP_IMAGE"
188+
echo "$DOCKER_METADATA_OUTPUT_TAGS" | tr ' ' '\n' | xargs -n1 docker tag "$DOCKER_APP_IMAGE"
189+
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:)"

.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

docker-compose.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
services:
2-
bfs:
2+
app:
33
build: .
44
command: watch --interval 10
5-
image: containers.lib.berkeley.edu/lap/bfs/development:latest
65
init: true
76
environment:
87
COA_APP_ID: "${COA_APP_ID}"
98
COA_APP_KEY: "${COA_APP_KEY}"
9+
BFS_SFTP_USER: "${BFS_SFTP_USER}"
1010
volumes:
11-
- ./:/opt/app-root/src:rw
11+
- ./:/opt/app:rw
1212
- ./secrets:/run/secrets:ro
1313
secrets:
1414
- source: SSH_KEY
15-
target: /opt/app/src/.ssh/id_rsa
15+
target: /opt/app/.ssh/id_rsa
1616
uid: "40061"
1717
gid: "40061"
1818
mode: 0400
1919

2020
secrets:
2121
SSH_KEY:
2222
file: secrets/SSH_KEY
23-
24-
version: "3.8"

0 commit comments

Comments
 (0)