Skip to content

Commit

Permalink
feat: Release docker version (#2)
Browse files Browse the repository at this point in the history
* test

* added template page with colors

* completed colors logic

* added thanks to mmumshad

* force push

* fix github workflow

* primo

* more tags

* give release plugins
  • Loading branch information
diegolagospagopa authored Jun 3, 2022
1 parent f9f002a commit 24f0638
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 52 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/docker-github-packages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Create and publish a Docker image

on:
push:
branches:
- "docker-repo"
tags:
- "v*"

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
55 changes: 55 additions & 0 deletions .github/workflows/pr-title.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: "Validate PR title"

on:
pull_request_target:
types:
- opened
- edited
- synchronize

jobs:
main:
name: Validate PR title
runs-on: ubuntu-latest
steps:
# Please look up the latest version from
# https://github.com/amannn/action-semantic-pull-request/releases
- uses: amannn/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# Configure which types are allowed.
# Default: https://github.com/commitizen/conventional-commit-types
types: |
fix
feat
docs
chore
breaking
# Configure that a scope must always be provided.
requireScope: false
# Configure additional validation for the subject based on a regex.
# This example ensures the subject starts with an uppercase character.
subjectPattern: ^[A-Z].+$
# If `subjectPattern` is configured, you can use this property to override
# the default error message that is shown when the pattern doesn't match.
# The variables `subject` and `title` can be used within the message.
subjectPatternError: |
The subject "{subject}" found in the pull request title "{title}"
didn't match the configured pattern. Please ensure that the subject
starts with an uppercase character.
# For work-in-progress PRs you can typically use draft pull requests
# from Github. However, private repositories on the free plan don't have
# this option and therefore this action allows you to opt-in to using the
# special "[WIP]" prefix to indicate this state. This will avoid the
# validation of the PR title and the pull request checks remain pending.
# Note that a second check will be reported if this is enabled.
wip: true
# When using "Squash and merge" on a PR with only one commit, GitHub
# will suggest using that commit message instead of the PR title for the
# merge commit, and it's easy to commit this by mistake. Enable this option
# to also validate the commit message for one commit PRs.
validateSingleCommit: true
# Related to `validateSingleCommit` you can opt-in to validate that the PR
# title matches a single commit to avoid confusion.
validateSingleCommitMatchesPrTitle: true
33 changes: 33 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Release

on:
# Trigger the workflow on push or pull request,
# but only for the main branch
push:
branches:
- release-dev
paths-ignore:
- "CODEOWNERS"
- "**.md"
- ".**"

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
persist-credentials: false
fetch-depth: 0

- name: Release
uses: cycjimmy/semantic-release-action@v3
with:
semantic_version: 19.0.2
extra_plugins: |
@semantic-release/[email protected]
@semantic-release/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# devops-springboot-gitlab-workflow

Application written in Spring boot to test pipelines using the gitlab workflow

## Thanks to

<https://github.com/mmumshad/simple-webapp-color> for the idea about colors
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>


<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package it.pagopa.devops.springbootshowcase;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/app")
public class AppController {

@Value("${MY_ENV_1:}")
private String myEnv1;

@GetMapping(path = "/", produces=MediaType.APPLICATION_JSON_VALUE)
public Map<String, String> root()
{
HashMap<String, String> map = new HashMap<>();
map.put("root", "ok");
return map;
}

@GetMapping(path = "/status", produces=MediaType.APPLICATION_JSON_VALUE)
public Map<String, String> status()
{
HashMap<String, String> map = new HashMap<>();
map.put("status", "ok");
return map;
}

@GetMapping(path = "/envs", produces=MediaType.APPLICATION_JSON_VALUE)
public Map<String, String> envs()
{
HashMap<String, String> map = new HashMap<>();
map.put("MY_ENV_1", myEnv1);
return map;
}
}
Original file line number Diff line number Diff line change
@@ -1,64 +1,40 @@
package it.pagopa.devops.springbootshowcase;

import java.util.HashMap;
import java.util.Map;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.ModelAndView;
import java.util.Random;

@RestController
@RequestMapping("/")
@Controller
public class RootController {

@Value("${MY_ENV_1:}")
private String myEnv1;
private List<String> colors = Arrays.asList(new String[]{"red","green","blue","blue2","darkblue","pink","lightgoldenrodyellow","black"});

@GetMapping(path = "/", produces=MediaType.APPLICATION_JSON_VALUE)
public Map<String, String> root()
{
HashMap<String, String> map = new HashMap<>();
map.put("root", "ok");
return map;
@GetMapping("/")
public ModelAndView passParametersWithModelAndView() throws UnknownHostException {
ModelAndView modelAndView = new ModelAndView("indexTemplate");
modelAndView.addObject("color", getOneColor(""));
modelAndView.addObject("hostname", InetAddress.getLocalHost().getHostName());
return modelAndView;
}

@GetMapping(path = "/status", produces=MediaType.APPLICATION_JSON_VALUE)
public Map<String, String> status()
{
HashMap<String, String> map = new HashMap<>();
map.put("status", "ok");
return map;
}


@GetMapping(path = "/envs", produces=MediaType.APPLICATION_JSON_VALUE)
public Map<String, String> envs()
{
HashMap<String, String> map = new HashMap<>();
System.getenv().forEach((k, v) -> {
map.put(k, v);
});
return map;
}

/*
* Liveness & Readiness
*/
@GetMapping(path = "/live", produces=MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public String live()
{
return "live";
}
private String getOneColor(String choiseColor){
Random r = new Random();

@GetMapping(path = "/ready", produces=MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public String ready()
{
return "ready";
if (choiseColor != null && choiseColor != ""){
return colors.stream()
.filter(color -> color.equals(choiseColor))
.findAny()
.orElse(null);
} else {
return colors.get(r.nextInt(colors.size()));
}
}

}
3 changes: 1 addition & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
logging.level.org.springframework=INFO
logging.level.com.howtodoinjava=INFO
logging.level.org.springframework=DEBUG

#output to a temp_folder/file
logging.file=${java.io.tmpdir}/application.log
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/templates/indexTemplate.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<title>Hello from PagoPA</title>
<body th:style="'background:' + ${color} + ';'"></body>
<div style="color: #e4e4e4;
text-align: center;
height: 90px;
vertical-align: middle;">

<h1 style="font-size: 5em;" th:text="${hostname}"></h1>

</div>

0 comments on commit 24f0638

Please sign in to comment.