Skip to content

Commit

Permalink
Initial commit with service and CI/CD
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsfernandez committed Jun 6, 2024
1 parent 359c88c commit 557365c
Show file tree
Hide file tree
Showing 29 changed files with 1,073 additions and 1 deletion.
29 changes: 29 additions & 0 deletions .github/actions/image-env-name/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: 'Compute Image Name for Env'
description: 'Computes the final image name based on the environment'
inputs:
base-image-name:
description: 'Base image name'
required: true
main-branch-name:
description: "Main branch of repository"
required: false
default: "master"
outputs:
image_name:
description: "Final image name"
value: ${{ steps.image-env-name.outputs.image_name }}
runs:
using: "composite"
steps:
- name: Setup Image Name for Env
id: image-env-name
run: |
if [[ ${{ github.ref }} == 'refs/heads/${{ inputs.main-branch-name }}' ]]; then
echo "image_name=${{ inputs.base-image-name }}" >> $GITHUB_OUTPUT
elif [[ ${{ github.ref }} == 'refs/heads/test/'* ]]; then
echo "image_name=${{ inputs.base-image-name }}-dev" >> $GITHUB_OUTPUT
else
echo "::error::Unsupported branch name"
exit 1
fi
shell: bash
15 changes: 15 additions & 0 deletions .github/actions/tag-branch-name/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: 'Compute Image Tag for Branch and Env'
description: 'Compute Image Tag for Branch and Env'
outputs:
tag:
description: "Tag"
value: ${{ steps.tag-branch-name.outputs.tag }}
runs:
using: "composite"
steps:
- name: Setup Branch Name for Tag
id: tag-branch-name
run: |
RESULT=$(echo "${{github.ref_name}}.${{github.run_number}}" | tr / -)
echo "tag=$RESULT" >> $GITHUB_OUTPUT
shell: bash
61 changes: 61 additions & 0 deletions .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Publish Image

on:
push:
branches: [main, test/*]

jobs:
publish:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'

- name: Setup Gradle
uses: gradle/gradle-build-action@v2

# Need to do this at the start to be able to use test containers
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Gradle build
run: ./gradlew build
shell: bash

- name: Setup Image Name for Env
id: image-env-name
uses: ./.github/actions/image-env-name
with:
base-image-name: snippet-asset-service
main-branch-name: "main"

- name: Setup Branch Name for Tag
id: tag-branch-name
uses: ./.github/actions/tag-branch-name

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: austral-ingsis
password: ${{ secrets.GITHUB_TOKEN }}

- name: Push to GitHub Container Registry
id: docker_build
uses: docker/build-push-action@v4
with:
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/austral-ingsis/${{ steps.image-env-name.outputs.image_name }}:${{ steps.tag-branch-name.outputs.tag }}
ghcr.io/austral-ingsis/${{ steps.image-env-name.outputs.image_name }}
40 changes: 40 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

### Kotlin ###
.kotlin
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM gradle:8.7.0-jdk17-jammy AS build
COPY . /app
WORKDIR /app
RUN ./gradlew bootJar

FROM eclipse-temurin:17-jre-jammy
EXPOSE 8080
RUN mkdir /app
COPY --from=build /app/build/libs/asset-service.jar /app/asset-service.jar
COPY newrelic/newrelic.jar /app/newrelic.jar
ENTRYPOINT ["java", "-jar", "-Dspring.profiles.active=production","-javaagent:/app/newrelic.jar","/app/asset-service.jar"]
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# asset-service
# Snippet Searcher Asset Service
Service of the Snippet Searcher platform in charge of storing assets to a bucket.

### How to use this API?

Start the docker image and go to "http://localhost:8080/swagger-ui"

### How to use this Docker Image

To see configurations: see `docker-compose.yml` file.
This image is uploaded to Github Container Registry so you will have to search their docs to know how to pull it.
70 changes: 70 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id 'org.springframework.boot' version '3.2.5'
id 'io.spring.dependency-management' version '1.1.4'
id 'org.jetbrains.kotlin.jvm' version '1.9.23'
id 'org.jetbrains.kotlin.plugin.spring' version '1.9.23'
}

group = 'org.snippet'
version = '0.0.1-SNAPSHOT'

java {
sourceCompatibility = '17'
}

bootJar {
archiveFileName = "${archiveBaseName.get()}.${archiveExtension.get()}"
}

configurations {
compileOnly {
extendsFrom annotationProcessor
}
}

repositories {
mavenCentral()
}

ext {
set('springCloudAzureVersion', "5.11.0")
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'com.azure.spring:spring-cloud-azure-starter-storage'
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin'
implementation 'io.projectreactor.kotlin:reactor-kotlin-extensions'
implementation 'org.jetbrains.kotlin:kotlin-reflect'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-reactor'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'

testImplementation "com.playtika.testcontainers:embedded-azurite:3.1.6"
testImplementation "org.springframework.cloud:spring-cloud-starter-bootstrap:4.1.2"

implementation "org.springdoc:springdoc-openapi-starter-webflux-api:2.5.0"
implementation "org.springdoc:springdoc-openapi-starter-webflux-ui:2.5.0"
}

dependencyManagement {
imports {
mavenBom "com.azure.spring:spring-cloud-azure-dependencies:${springCloudAzureVersion}"
}
}

tasks.withType(KotlinCompile) {
kotlinOptions {
freeCompilerArgs += '-Xjsr305=strict'
jvmTarget = '17'
}
}

tasks.named('test') {
useJUnitPlatform()
}
29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: "3.9"

services:

api:
container_name: "asset_service"
image: ghcr.io/austral-ingsis/snippet-asset-service:latest
ports:
- "8080:8080"
environment:
AZURE_HOST: "http://azurite"
NEW_RELIC_AGENT_ENABLED: false


azurite:
image: mcr.microsoft.com/azure-storage/azurite
container_name: "azurite"
hostname: azurite
restart: always
ports:
- "10000:10000"
- "10001:10001"
- "10002:10002"
volumes:
- blob:/workspace

volumes:
blob:
external: false
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 557365c

Please sign in to comment.