Skip to content

Commit ddf7758

Browse files
Improve build.sbt
1 parent e24fb20 commit ddf7758

File tree

7 files changed

+322
-245
lines changed

7 files changed

+322
-245
lines changed

.github/scripts/dnd-sbt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash -exu
2+
SCRIPT_HOME="$(cd "$(dirname "$0")"; pwd)"
3+
COMPONENT_HOME="$(cd "${SCRIPT_HOME}/../.."; pwd)"
4+
5+
cd "${COMPONENT_HOME}"
6+
7+
tmp_dir=$(mktemp -d -t dnd-sbt-XXXXXXXXXX)
8+
cp -R . ${tmp_dir}
9+
10+
docker run \
11+
-v /var/run/docker.sock:/var/run/docker.sock \
12+
-v /usr/bin/docker:/usr/bin/docker \
13+
-v ${HOME}/.docker/config.json:/root/.docker/config.json \
14+
-v ${tmp_dir}:/root/ \
15+
-e GITHUB_TOKEN=${GITHUB_TOKEN} \
16+
sbtscala/scala-sbt:eclipse-temurin-jammy-21.0.2_13_1.9.9_2.12.19 \
17+
/bin/bash -c "git config --global --add safe.directory /root; sbt ${1}"

.github/workflows/ci.yaml

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,36 @@
11
name: CI
2-
32
on:
43
pull_request:
54
paths:
6-
- '**/*.scala'
7-
- '**/*.sbt'
8-
- '.scalafmt.conf'
9-
- 'project/**'
10-
- '.github/workflows/ci.yaml'
5+
- .github/workflows/ci.yaml
6+
- .sbtopts
7+
- build.sbt
8+
- .scalafmt.conf
9+
- project/**
10+
- src/**
11+
12+
defaults:
13+
run:
14+
shell: bash
1115

1216
env:
13-
SBT_OPTS: "-Xmx2G -XX:+UseG1GC -Xss2M"
1417
GITHUB_TOKEN: ${{ secrets.READ_PACKAGES }}
1518

1619
jobs:
17-
lint:
18-
runs-on: ubuntu-latest
19-
20+
code-check:
21+
runs-on: self-hosted
22+
container:
23+
image: sbtscala/scala-sbt:eclipse-temurin-jammy-21.0.2_13_1.9.9_2.12.19
24+
options: --user 1001:1001
2025
steps:
2126
- uses: actions/checkout@v4
22-
- uses: actions/setup-java@v4
23-
with:
24-
distribution: 'temurin'
25-
java-version: '21'
26-
- uses: sbt/setup-sbt@v1
27-
with:
28-
sbt-runner-version: 1.9.9
29-
- run: sbt scalafmtCheckAll
3027
- run: sbt headerCheckAll
31-
28+
- run: sbt scalafmtCheckAll
3229
test:
33-
runs-on: ubuntu-latest
30+
runs-on: self-hosted
31+
container:
32+
image: sbtscala/scala-sbt:eclipse-temurin-jammy-21.0.2_13_1.9.9_2.12.19
33+
options: --user 1001:1001
3434
steps:
3535
- uses: actions/checkout@v4
36-
- uses: actions/setup-java@v4
37-
with:
38-
distribution: 'temurin'
39-
java-version: '21'
40-
- uses: sbt/setup-sbt@v1
41-
with:
42-
sbt-runner-version: 1.9.9
43-
- name: Run tests
44-
run: sbt clean test
45-
46-
- name: Upload test results
47-
if: always()
48-
uses: actions/upload-artifact@v4
49-
with:
50-
name: test-results
51-
path: target/test-results
36+
- run: sbt clean compile Test/compile

.github/workflows/docker-ci.yaml

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,70 @@
11
name: Docker CI
2-
32
on:
43
pull_request:
54
paths:
65
- .github/workflows/docker-ci.yaml
6+
- .github/scripts/**
77
- build.sbt
8+
- src/**
9+
10+
env:
11+
GITHUB_TOKEN: ${{ secrets.READ_PACKAGES }}
812

913
jobs:
10-
docker-build:
11-
runs-on: ubuntu-latest
14+
build-and-test:
15+
name: Build & Test
16+
runs-on: self-hosted
1217
steps:
1318
- uses: actions/checkout@v4
14-
- uses: docker/setup-buildx-action@v3
15-
- uses: actions/setup-java@v4
16-
with:
17-
distribution: 'temurin'
18-
java-version: '21'
19-
- uses: sbt/setup-sbt@v1
20-
with:
21-
sbt-runner-version: 1.9.9
19+
2220
- name: Build Docker image
23-
env:
24-
GITHUB_TOKEN: ${{ secrets.READ_PACKAGES }}
25-
run: sbt docker/Docker/publishLocal
21+
run: |
22+
.github/scripts/dnd-sbt Docker/publishLocal
23+
IMAGE_NAME=$(.github/scripts/dnd-sbt printDockerImageName | grep DOCKER_IMAGE | cut -d= -f2)
24+
echo "IMAGE=${IMAGE_NAME}" >> $GITHUB_ENV
25+
26+
- name: Test image - run container
27+
run: |
28+
CONTAINER_ID=$(docker run -d -p 50051 ${IMAGE})
29+
echo "CONTAINER_ID=${CONTAINER_ID}" >> $GITHUB_ENV
30+
HOST_PORT=$(docker port ${CONTAINER_ID} 50051 | cut -d':' -f2)
31+
echo "HOST_PORT=${HOST_PORT}" >> $GITHUB_ENV
32+
sleep 15
33+
34+
- name: Test image - verify service is running
35+
run: |
36+
nc -z localhost ${HOST_PORT}
37+
if [ $? -ne 0 ]; then
38+
echo "Service check failed!"
39+
exit 1
40+
fi
41+
42+
- name: Cleanup container
43+
if: always()
44+
run: |
45+
if [ ! -z "${CONTAINER_ID}" ]; then
46+
docker stop ${CONTAINER_ID}
47+
docker rm ${CONTAINER_ID}
48+
fi
49+
50+
security-scan:
51+
name: Security Scan
52+
runs-on: self-hosted
53+
steps:
54+
- uses: actions/checkout@v4
55+
56+
- name: Build Docker image
57+
run: |
58+
.github/scripts/dnd-sbt Docker/publishLocal
59+
IMAGE_NAME=$(.github/scripts/dnd-sbt printDockerImageName | grep DOCKER_IMAGE | cut -d= -f2)
60+
echo "IMAGE=${IMAGE_NAME}" >> $GITHUB_ENV
61+
62+
- name: Run Trivy vulnerability scanner
63+
uses: aquasecurity/trivy-action@master
64+
with:
65+
image-ref: ${{ env.IMAGE }}
66+
format: 'table'
67+
exit-code: '1'
68+
ignore-unfixed: true
69+
vuln-type: 'os,library'
70+
severity: 'CRITICAL,HIGH'

.github/workflows/publish.yaml

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,50 +11,71 @@ env:
1111

1212
jobs:
1313
publish-jars:
14-
runs-on: ubuntu-latest
14+
runs-on: self-hosted
15+
container:
16+
image: sbtscala/scala-sbt:eclipse-temurin-jammy-21.0.2_13_1.9.9_2.12.19
17+
options: --user 1001:1001
1518
steps:
1619
- uses: actions/checkout@v4
1720
with:
1821
fetch-depth: 0
19-
- uses: actions/setup-java@v4
20-
with:
21-
distribution: 'temurin'
22-
java-version: '21'
23-
- uses: sbt/setup-sbt@v1
24-
with:
25-
sbt-runner-version: 1.9.9
26-
- name: publish
22+
- name: sbt publish
2723
run: sbt clean publish
2824
publish-docker-image:
2925
runs-on: self-hosted
26+
outputs:
27+
should_trigger_deploy: ${{ steps.should_trigger_deploy.outputs.should_trigger_deploy }}
3028
steps:
3129
- uses: actions/checkout@v4
3230
with:
3331
fetch-depth: 0
34-
- uses: actions/setup-java@v4
35-
with:
36-
distribution: 'temurin'
37-
java-version: '21'
38-
- uses: sbt/setup-sbt@v1
39-
with:
40-
sbt-runner-version: 1.9.9
41-
- uses: docker/setup-buildx-action@v3
4232
- uses: docker/login-action@v3
4333
with:
4434
registry: ghcr.io
4535
username: ${{ github.actor }}
4636
password: ${{ secrets.WRITE_PACKAGES }}
4737
logout: false
4838
- name: publish docker images
49-
run: sbt docker/Docker/publish
39+
run: .github/scripts/dnd-sbt Docker/publish
40+
- name: set should_trigger_deploy
41+
id: should_trigger_deploy
42+
shell: bash
43+
run: |
44+
pattern='^refs/tags/v[0-9]+\.0\.0$'
45+
echo "should_trigger_deploy=$([[ "$GITHUB_REF" =~ $pattern ]] && echo false || echo true)" >> $GITHUB_OUTPUT
5046
gh-release:
5147
needs: [publish-jars, publish-docker-image]
5248
runs-on: self-hosted
5349
steps:
50+
- uses: actions/checkout@v4
51+
with:
52+
fetch-depth: 0
5453
- uses: softprops/action-gh-release@v2
5554
with:
5655
token: ${{ secrets.RAW_CI_PAT }}
5756
generate_release_notes: true
5857
draft: false
5958
prerelease: ${{ contains(github.ref_name, '-') }}
6059
tag_name: ${{ github.ref_name }}
60+
trigger-deploy:
61+
needs: publish-docker-image
62+
if: needs.publish-docker-image.outputs.should_trigger_deploy == 'true'
63+
runs-on: ubuntu-latest
64+
steps:
65+
- name: tag without 'v' prefix
66+
id: extract_tag
67+
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
68+
- name: trigger mvp-deployer workflow
69+
uses: peter-evans/repository-dispatch@v3
70+
with:
71+
token: ${{ secrets.RAW_CI_PAT }}
72+
repository: raw-labs/mvp-deployer
73+
event-type: das-salesforce-integration-cd
74+
client-payload: |-
75+
{
76+
"aws_region": "eu-west-1",
77+
"raw_version": "${{ steps.extract_tag.outputs.version }}",
78+
"target_env": "integration",
79+
"loaded_vars": "integration",
80+
"deployer_version": "latest"
81+
}

README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,30 @@
1111

1212
## How to use
1313

14-
First you need to build the project:
14+
### Prerequisites
15+
16+
You need to have [sbt](https://www.scala-sbt.org/) installed to build the project.
17+
18+
You can install sbt using [sdkman](https://sdkman.io/):
19+
```bash
20+
$ sdk install sbt
21+
```
22+
23+
### Running the server
24+
25+
You can run the server with the following command:
1526
```bash
16-
$ sbt "project docker" "docker:publishLocal"
27+
$ sbt run
1728
```
1829

19-
This will create a docker image with the name `das-excel`.
30+
### Docker
31+
32+
To run the server in a docker container you need to follow these steps:
33+
34+
First, you need to build the project:
35+
```bash
36+
$ sbt "docker:publishLocal"
37+
```
2038

2139
Then you can run the image with the following command:
2240
```bash

0 commit comments

Comments
 (0)