diff --git a/.github/workflows/publish-docker-image-prod.yml b/.github/workflows/publish-docker-image-prod.yml new file mode 100644 index 000000000..2db8832d2 --- /dev/null +++ b/.github/workflows/publish-docker-image-prod.yml @@ -0,0 +1,38 @@ +name: Publish api-server Docker image to DockerHub + +on: + workflow_dispatch: + release: + types: [published] + +jobs: + push_to_registry: + name: Push Docker image to Docker Hub + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: wiseberkeley/wise-api-server + flavor: latest=true + tags: | + type=semver,pattern={{version}} + type=sha + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/maven.yml b/.github/workflows/release.yml similarity index 63% rename from .github/workflows/maven.yml rename to .github/workflows/release.yml index 68238492d..2d2e7a08c 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/release.yml @@ -1,17 +1,21 @@ # This workflow will build a Java project with Maven # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven -name: Java CI with Maven +name: Build API and release on GitHub on: [push, pull_request] jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: - java-version: 1.8 + node-version: 20 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: 17 - name: Build with Maven run: mvn -B package --file pom.xml - name: Release diff --git a/Dockerfile b/Dockerfile index 8eb965a45..efe9e0742 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,12 @@ -FROM maven:3.9.6-eclipse-temurin-17 +# Generate wise-api-server Docker image +# Stage 1: Build application +FROM maven:3.9.6-eclipse-temurin-17 as build WORKDIR /app +COPY . . +RUN mvn package -COPY pom.xml . -RUN mvn dependency:go-offline - -COPY src/ /app/src/ - -CMD mvn spring-boot:run -Dspring-boot.run.profiles=dockerdev +# Stage 2: Copy war +FROM eclipse-temurin:17 +COPY --from=build /app/target/wise.war wise.war +ENTRYPOINT ["java","-jar","/wise.war", "--spring.config.location=/application.properties"] diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 000000000..1d7186233 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,8 @@ +# Generate wise-api-dev Docker image + +FROM maven:3.9.6-eclipse-temurin-17 +WORKDIR /app +COPY pom.xml . +RUN mvn dependency:go-offline +COPY src/ /app/src/ +CMD mvn spring-boot:run -Dspring-boot.run.profiles=dockerdev