Skip to content

Instantly share code, notes, and snippets.

@abdulhadad
Last active September 18, 2018 10:40
Show Gist options
  • Save abdulhadad/f5f3ed6008c2e740d0d0ffd79f9cbab8 to your computer and use it in GitHub Desktop.
Save abdulhadad/f5f3ed6008c2e740d0d0ffd79f9cbab8 to your computer and use it in GitHub Desktop.
Spring Getting Started ke Release Git Server dan Nexus
version: "2"
networks:
gitea:
external: false
services:
gitea:
image: gitea/gitea:latest
environment:
- USER_UID=1000
- USER_GID=1000
restart: always
networks:
- gitea
volumes:
- ./gitea:/data
ports:
- "3000:3000"
- "222:22"

Spring Getting Started ke Release Git Server dan Nexus

compile sample project

git clone https://github.com/spring-guides/gs-rest-service.git cd gs-rest-service/complete mvn clean package

install

[INFO] Installing /home/gk/PerbenMvnRelease/gs-rest-service/complete/target/gs-rest-service-0.1.0.jar to /home/gk/.m2/repository/org/springframework/gs-rest-service/0.1.0/gs-rest-service-0.1.0.jar
[INFO] Installing /home/gk/PerbenMvnRelease/gs-rest-service/complete/pom.xml to /home/gk/.m2/repository/org/springframework/gs-rest-service/0.1.0/gs-rest-service-0.1.0.pom

buat simulasi gitea

  • clone docker pull gitea/gitea:latest

  • buat file docker compose gitea.yml

version: "2"

networks:
  gitea:
    external: false

services:
  gitea:
    image: gitea/gitea:latest
    environment:
      - USER_UID=1000
      - USER_GID=1000
    restart: always
    networks:
      - gitea
    volumes:
      - ./gitea:/data
    ports:
      - "3000:3000"
      - "222:22"
cp -a gs-rest-service/complete gs-rest-service-complete
cd gs-rest-service-complete
git init
git add .
git commit -m "initial"
git status
git remote add origin http://localhost:3000/gitea/gs-rest-service-complete.git
# git remote show origin
# git remote -v
# git remote set-url origin http://localhost:3000/gitea/gs-rest-service.git
git push -u origin master

buat simulasi nexus

  • Pull image docker pull sonatype/nexus3
  • buat file docker compose nexus.yml
version: "2"

networks:
  nexus:
    external: false

services:
  nexus:
    image: sonatype/nexus3:latest
    restart: always
    networks:
      - nexus
    volumes:
      - ./nexus-data:/sonatype-work
    ports:
      - "8081:8081"
  • Jalankan docker-compose -f nexus.yml up -d , lama startupnya
  • Debugging dengan docker-compose -f nexus.yml ps dan docker-compose -f nexus.yml logs -f
  • Buka halaman http://localhost:8081/ , password default u:admin p:admin123

upload artifak ke nexus

  • tambahkan pom.xml
<distributionManagement>
   <snapshotRepository>
      <id>nexus-snapshots</id>
      <url>http://localhost:8081/nexus/content/repositories/snapshots</url>
   </snapshotRepository>
	<repository>
		<id>nexus-releases</id>
		<url>http://localhost:8081/repository/maven-releases/</url>
	</repository>
</distributionManagement>
  • buat atau edit ~/.m2/settings.xml
  • Untuk mendeploy ke snapshot ubah pom.xml bagian <version>0.1.0-SNAPSHOT</version>
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">

<servers>
   <server>
      <id>nexus-snapshots</id>
      <username>admin</username>
      <password>admin123</password>
   </server>
   <server>
      <id>nexus-releases</id>
      <username>admin</username>
      <password>admin123</password>
   </server>

</servers>
</settings>

maven release ke git dan nexus

  • buat berkas .gitignore
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
  • pastikan di working dir tidak ada kondisi unstaged dan staged cek via git status. kondisi bisa di diselesaikan dengan melakukan commit git add . && git commit -m "Contoh commit"
  • tambahkan di pom.xml konfigurasi git
<properties>
	...
   <project.scm.id>gitea</project.scm.id>
</properties>
...
<scm>
   <connection>scm:git:http://localhost:3000/gitea/gs-rest-service-complete.git</connection>
   <url>http://localhost:3000/gitea/gs-rest-service-complete</url>
   <developerConnection>scm:git:http://localhost:3000/gitea/gs-rest-service-complete.git</developerConnection>
</scm>
  • tambahkan di settings.xml otentikasi git
   <server>
      <id>gitea</id>
      <username>gitea</username>
      <password>R@has14iz3</password>
   </server>
  • Jalankan mvn release:clean release:prepare release:perform -DreleaseVersion=0.1.0 -DdevelopmentVersion=0.1.0-SNAPSHOT
  • Cek history commit, tag di git server
  • Lihat artifak di nexus

Referensi

version: "2"
networks:
nexus:
external: false
services:
nexus:
image: sonatype/nexus3:latest
restart: always
networks:
- nexus
volumes:
- ./nexus-data:/sonatype-work
ports:
- "8081:8081"
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>gs-rest-service</artifactId>
<version>0.1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
<project.scm.id>gitea</project.scm.id>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
<distributionManagement>
<snapshotRepository>
<id>nexus-snapshots</id>
<url>http://localhost:8081/repository/maven-snapshots/</url>
</snapshotRepository>
<repository>
<id>nexus-releases</id>
<url>http://localhost:8081/repository/maven-releases/</url>
</repository>
</distributionManagement>
<scm>
<connection>scm:git:http://localhost:3000/gitea/gs-rest-service-complete.git</connection>
<url>http://localhost:3000/gitea/gs-rest-service-complete</url>
<developerConnection>scm:git:http://localhost:3000/gitea/gs-rest-service-complete.git</developerConnection>
<tag>HEAD</tag>
</scm>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<servers>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>gitea</id>
<username>gitea</username>
<password>R@has14iz3</password>
</server>
</servers>
</settings>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment