Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

let CI publish Docker image, tweak Dockerfile #214

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ aliases:
echo 'export CIRCLE_SHA1="$CIRCLE_SHA1"' >> $BASH_ENV
echo 'export CIRCLE_PROJECT_REPONAME="$CIRCLE_PROJECT_REPONAME"' >> $BASH_ENV
.circleci/trigger_build_v2.sh "entur/lamassu-deployment-config.git" "master" "$(git log -1 --pretty=%B)"
- &docker-build
name: Docker build
command: |
DOCKER_BUILDKIT=1 docker build .

jobs:
test:
Expand Down Expand Up @@ -108,18 +104,6 @@ jobs:
# Cannot use -o because of snapshot dependencies.
- run: mvn deploy -s .circleci/settings.xml -P prettierSkip -DskipTests
- run: *post_build
docker-build:
docker:
- image: cimg/openjdk:17.0.8
auth:
username: $DOCKERHUB_LOGIN
password: $DOCKERHUB_PASSWORD
steps:
- setup_remote_docker:
version: 20.10.24
- checkout
- run: *docker-build

workflows:
version: 2.1
release:
Expand All @@ -135,7 +119,4 @@ workflows:
only:
- master
requires:
- test-release
- docker-build:
name: docker-build
context: global
- test-release
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
/.git

/Dockerfile

/target
# !**/src/main/**/target/
# !**/src/test/**/target/

/.circleci
/.github

### STS ###
.apt_generated
.classpath
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/publish-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: build Docker image, optionally publish it

on:
push:
branches:
- '*'
pull_request:
branches:
- '*'

jobs:
test:
name: test
uses: './.github/workflows/test.yml'

build-publish:
needs: [test]
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4

- name: set up Docker buildx
uses: docker/setup-buildx-action@v2
- name: log into the Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: build and push Docker image
uses: docker/build-push-action@v4
with:
push: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'ci-docker-push') }}
tags: |
entur/lamassu:latest
platforms: linux/amd64,linux/arm64
# https://docs.docker.com/build/ci/github-actions/cache/#cache-backend-api
cache-from: type=gha
cache-to: type=gha,mode=max
46 changes: 46 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: test

on:
push:
branches:
- '*'
pull_request:
branches:
- '*'
# make workflow "callable" by others
workflow_call:

jobs:
test:
runs-on: ubuntu-latest
env:
JFROG_USER: ${{ secrets.ARTIFACTORY_USER }}
JFROG_PASS: ${{ secrets.ARTIFACTORY_PASSWORD }}
steps:
- name: checkout
uses: actions/checkout@v4
- name: download Maven settings
run: |
wget https://raw.githubusercontent.com/entur/circleci-toolbox-image-java11/master/tools/m2/settings.xml -O mvn-settings.xml

- name: refresh Maven cache
run: |
mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.0:go-offline -s mvn-settings.xml

# Cannot use -o because of snapshot dependencies.
- name: run Maven verify
run: |
mvn verify -s mvn-settings.xml

- name: Sonar scan
run: |
mvn -s mvn-settings.xml \
org.jacoco:jacoco-maven-plugin:prepare-agent verify \
org.jacoco:jacoco-maven-plugin:report sonar:sonar \
-Dmaven.main.skip \
-DskipTests \
-Dsonar.projectKey=entur_${{ github.event.repository.name }} \
-Dsonar.organization=${{ secrets.SONAR_ORG }} \
-Dsonar.projectName=${{ github.event.repository.name }} \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.login=${{ secrets.SONAR_PASSWORD }}
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ RUN --mount=type=bind,source=pom.xml,target=pom.xml \
env CI=true \
./mvnw install -DskipTests -P prettierSkip

FROM eclipse-temurin:17.0.8_7-jdk-alpine
FROM eclipse-temurin:17.0.8_7-jre-alpine

RUN apk update && apk upgrade && apk add --no-cache \
tini
Expand All @@ -32,6 +32,9 @@ WORKDIR /home/appuser
RUN chown -R appuser:appuser /home/appuser
USER appuser

EXPOSE 8080
EXPOSE 9001

# todo: don't hard-code lamassu's version here
COPY --from=builder target/lamassu-0.0.1-SNAPSHOT.jar lamassu.jar

Expand Down
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,12 @@
</build>
</profile>
</profiles>
<repositories>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>https://repo1.maven.org/maven2</url>
</repository>
</repositories>
</project>