Skip to content

Commit be0be63

Browse files
authored
feat: build and push docker image in ci workflow (#22)
1 parent 0fb5d1b commit be0be63

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

.github/workflows/ci.yml

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,46 @@ jobs:
2323
- name: Build with Maven
2424
run: mvn -B package --file pom.xml
2525

26-
- name: Run tests
27-
run: mvn test
26+
- name: Run tests with dev profile
27+
run: mvn test -Dspring.profiles.active=dev
28+
29+
- name: Upload test results
30+
if: always()
31+
uses: actions/upload-artifact@v4
32+
with:
33+
name: test-results
34+
path: target/surefire-reports/
35+
36+
docker:
37+
needs: build-test
38+
if: success() && github.ref == 'refs/heads/main'
39+
runs-on: ubuntu-latest
40+
41+
steps:
42+
- uses: actions/checkout@v4
43+
44+
- name: Set up Docker Buildx
45+
uses: docker/setup-buildx-action@v3
46+
47+
- name: Login to Docker Hub
48+
uses: docker/login-action@v3
49+
with:
50+
username: ${{ secrets.DOCKERHUB_USERNAME }}
51+
password: ${{ secrets.DOCKERHUB_TOKEN }}
52+
53+
- name: Extract version from pom.xml
54+
id: get_version
55+
run: |
56+
VERSION=$(grep -A 1 "<version>" pom.xml | grep -v "<version>" | head -1 | sed 's/[[:space:]]*<version>\(.*\)<\/version>.*/\1/')
57+
echo "VERSION=${VERSION}" >> $GITHUB_ENV
58+
59+
- name: Build and push Docker image
60+
uses: docker/build-push-action@v5
61+
with:
62+
context: .
63+
push: true
64+
tags: |
65+
${{ secrets.DOCKERHUB_USERNAME }}/jwt-auth-server:latest
66+
${{ secrets.DOCKERHUB_USERNAME }}/jwt-auth-server:${{ env.VERSION }}
67+
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/jwt-auth-server:buildcache
68+
cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/jwt-auth-server:buildcache,mode=max

src/main/java/com/example/jwt_auth_server/config/SecurityConfig.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
3737
.csrf(csrf -> csrf.disable())
3838
.authorizeHttpRequests(authorize -> authorize
3939
.requestMatchers("/", "/api/health", "/api/auth/**").permitAll()
40-
.requestMatchers("/h2-console/**").permitAll()
4140
.anyRequest().authenticated()
4241
)
4342
.sessionManagement(session -> session

0 commit comments

Comments
 (0)