Skip to content

Commit 43c25ae

Browse files
Merge pull request #250 from aodn/feature/5235-reference-stacmodel-from-codeartifact
Feature/5235 reference stacmodel from codeartifact
2 parents 9bc37c5 + f3df52d commit 43c25ae

10 files changed

Lines changed: 150 additions & 1 deletion

File tree

.github/environment/test.env

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
AWS_REGION=ap-southeast-2
2+
AWS_ROLE_ARN=arn:aws:iam::851725428481:role/AodnGitHubActionReadOnlyRole
3+
CODEARTIFACT_DOMAIN=central-aodn-org-au
4+
CODEARTIFACT_REPO=maven-aodn-store
5+
ECR_REGISTRY=851725428481.dkr.ecr.ap-southeast-2.amazonaws.com
6+
ECR_REPOSITORY=ogcapi-java

.github/workflows/build_deploy_edge.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,26 @@ jobs:
4545
aws-region: ${{ vars.AWS_REGION }}
4646
role-to-assume: ${{ vars.AWS_ROLE_ARN }}
4747

48+
- name: Get CodeArtifact Repository Authentication Token
49+
run: |
50+
TOKEN=$(aws codeartifact get-authorization-token \
51+
--domain ${{ vars.CODEARTIFACT_DOMAIN }} \
52+
--domain-owner ${{ steps.aws_auth.outputs.aws-account-id }} \
53+
--region ${{ vars.AWS_REGION }} \
54+
--query authorizationToken \
55+
--output text)
56+
echo "CODEARTIFACT_AUTH_TOKEN=$TOKEN" >> "$GITHUB_ENV"
57+
58+
- name: Get CodeArtifact Repository URL
59+
run: |
60+
REPO_URL=$(aws codeartifact get-repository-endpoint \
61+
--domain ${{ vars.CODEARTIFACT_DOMAIN }} \
62+
--repository ${{ vars.CODEARTIFACT_REPO }} \
63+
--format maven \
64+
--region ${{ vars.AWS_REGION }} \
65+
--output text)
66+
echo "CODEARTIFACT_REPO_URL=$REPO_URL" >> "$GITHUB_ENV"
67+
4868
- name: Build with Maven
4969
run: mvn -B verify --file pom.xml
5070

.github/workflows/test.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ permissions:
1717
jobs:
1818
build_test:
1919
runs-on: ubuntu-latest
20+
environment: test
2021
steps:
2122
- name: Checkout
2223
uses: actions/checkout@v4
@@ -40,6 +41,36 @@ jobs:
4041
distribution: 'temurin'
4142
java-version: '17'
4243
cache: 'maven'
44+
server-id: 'codeartifact'
45+
server-password: 'CODEARTIFACT_AUTH_TOKEN'
46+
47+
- name: Configure AWS Credentials
48+
id: aws_auth
49+
uses: aws-actions/configure-aws-credentials@v4
50+
with:
51+
audience: sts.amazonaws.com
52+
aws-region: ${{ vars.AWS_REGION }}
53+
role-to-assume: ${{ vars.AWS_ROLE_ARN }}
54+
55+
- name: Get CodeArtifact Repository Authentication Token
56+
run: |
57+
TOKEN=$(aws codeartifact get-authorization-token \
58+
--domain ${{ vars.CODEARTIFACT_DOMAIN }} \
59+
--domain-owner ${{ steps.aws_auth.outputs.aws-account-id }} \
60+
--region ${{ vars.AWS_REGION }} \
61+
--query authorizationToken \
62+
--output text)
63+
echo "CODEARTIFACT_AUTH_TOKEN=$TOKEN" >> "$GITHUB_ENV"
64+
65+
- name: Get CodeArtifact Repository URL
66+
run: |
67+
REPO_URL=$(aws codeartifact get-repository-endpoint \
68+
--domain ${{ vars.CODEARTIFACT_DOMAIN }} \
69+
--repository ${{ vars.CODEARTIFACT_REPO }} \
70+
--format maven \
71+
--region ${{ vars.AWS_REGION }} \
72+
--output text)
73+
echo "CODEARTIFACT_REPO_URL=$REPO_URL" >> "$GITHUB_ENV"
4374
4475
- name: Build with Maven
4576
run: mvn clean -B verify --file pom.xml

.mvn/codeartifact.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CA_DOMAIN=central-aodn-org-au
2+
CA_DOMAIN_OWNER=851725428481
3+
CA_REGION=ap-southeast-2
4+
CA_DURATION_SECONDS=43200
5+
CA_REPOSITORY=maven-aodn-store
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
wrapperVersion=3.3.4
2+
distributionType=only-script
3+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.8/apache-maven-3.9.8-bin.zip

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,32 @@ The server module contains the implementation of those interfaces, for details p
5454
|-------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
5555
| score | The min score value of the return record, the higher the value, the more relevance it will be. By default the score isn't set, it is Elastic Search field not STAC field |
5656

57+
# Use AWS CodeArtifact
58+
We are using AWS CodeArtifact to get stacmodel dependency deployed by es-indexer.
59+
60+
Since AWS CodeArtifact is private repository, and AWS CodeArtifact doesn't support direct mvn login,
61+
62+
So, please use:`./mvnw-ca install` to instead`mvn install` for dependency installation at root of the project.
63+
64+
Before running `./mvnw-ca install`, you need to:
65+
- Authenticate to AWS (export vars or refresh ~/.aws/credentials) using `AodnElevatedDeveloperAccess` role in `AODN-central` account (in which the images and artifacts of AODN are stored).
66+
- make sure you have settings.xml in your ~/.m2 folder. If not, run the following command:
67+
```bash
68+
cd ~/.m2
69+
cat > settings.xml << 'EOF'
70+
<!-- ~/.m2/settings.xml -->
71+
<settings>
72+
<servers>
73+
<server>
74+
<id>codeartifact</id>
75+
<username>aws</username>
76+
<password>${env.CODEARTIFACT_AUTH_TOKEN}</password>
77+
</server>
78+
</servers>
79+
</settings>
80+
81+
EOF
82+
```
5783

5884

5985
# Sort

mvnw-ca

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env sh
2+
# mvnw-ca: fetch AWS CodeArtifact token and repo URL
3+
4+
[ -f ".mvn/codeartifact.env" ] && . ".mvn/codeartifact.env"
5+
6+
if command -v aws >/dev/null 2>&1 &&
7+
[ -n "${CA_DOMAIN:-}" ] && [ -n "${CA_DOMAIN_OWNER:-}" ] && [ -n "${CA_REGION:-}" ]; then
8+
9+
# Get auth token if not set
10+
if [ -z "${CODEARTIFACT_AUTH_TOKEN:-}" ]; then
11+
CA_DURATION_SECONDS="${CA_DURATION_SECONDS:-43200}"
12+
CODEARTIFACT_AUTH_TOKEN="$(
13+
aws codeartifact get-authorization-token \
14+
--domain "$CA_DOMAIN" \
15+
--domain-owner "$CA_DOMAIN_OWNER" \
16+
--region "$CA_REGION" \
17+
--duration-seconds "$CA_DURATION_SECONDS" \
18+
--query authorizationToken --output text 2>/dev/null || true
19+
)"
20+
export CODEARTIFACT_AUTH_TOKEN
21+
fi
22+
23+
# Get repository URL if not set
24+
if [ -z "${CODEARTIFACT_REPO_URL:-}" ] && [ -n "${CA_REPOSITORY:-}" ]; then
25+
CODEARTIFACT_REPO_URL="$(
26+
aws codeartifact get-repository-endpoint \
27+
--domain "$CA_DOMAIN" \
28+
--domain-owner "$CA_DOMAIN_OWNER" \
29+
--repository "$CA_REPOSITORY" \
30+
--region "$CA_REGION" \
31+
--format maven \
32+
--query repositoryEndpoint --output text 2>/dev/null || true
33+
)"
34+
export CODEARTIFACT_REPO_URL
35+
else
36+
echo
37+
fi
38+
fi
39+
40+
exec mvn "$@"

pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
<id>repo.osgeo.org</id>
3737
<url>https://repo.osgeo.org/repository/release/</url>
3838
</repository>
39+
<repository>
40+
<id>codeartifact</id>
41+
<url>${env.CODEARTIFACT_REPO_URL}</url>
42+
</repository>
3943
</repositories>
4044
<modules>
4145
<module>common</module>
@@ -185,6 +189,11 @@
185189
<artifactId>log4j-layout-template-json</artifactId>
186190
<version>2.24.3</version> <!-- Check for the latest version -->
187191
</dependency>
192+
<dependency>
193+
<groupId>au.org.aodn</groupId>
194+
<artifactId>stacmodel</artifactId>
195+
<version>0.0.52</version>
196+
</dependency>
188197
</dependencies>
189198
</dependencyManagement>
190199
<distributionManagement>

server/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@
195195
<groupId>org.apache.logging.log4j</groupId>
196196
<artifactId>log4j-layout-template-json</artifactId>
197197
</dependency>
198+
<dependency>
199+
<groupId>au.org.aodn</groupId>
200+
<artifactId>stacmodel</artifactId>
201+
</dependency>
198202
<dependency>
199203
<groupId>org.springframework.boot</groupId>
200204
<artifactId>spring-boot-starter-test</artifactId>

server/src/main/java/au/org/aodn/ogcapi/server/core/model/ThemeModel.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package au.org.aodn.ogcapi.server.core.model;
22

3+
import au.org.aodn.stac.model.Citation;
34
import lombok.AllArgsConstructor;
45
import lombok.Builder;
56
import lombok.Data;
67
import lombok.NoArgsConstructor;
7-
88
import java.util.List;
99

1010
@Data
@@ -15,4 +15,9 @@ public class ThemeModel {
1515
protected String scheme;
1616
protected List<ConceptModel> concepts;
1717

18+
// This is just a test to make sure the stac model can be used in this module, we can remove it when all the stac models are using the stacmodel from es-indexer
19+
private void testStacmodelReference() {
20+
Citation citation = Citation.builder().build();
21+
}
22+
1823
}

0 commit comments

Comments
 (0)