Skip to content

Commit

Permalink
Merge pull request #213 from entur/dockerfile-build
Browse files Browse the repository at this point in the history
Dockerfile build
  • Loading branch information
testower authored Aug 21, 2023
2 parents 2c1c344 + 87fc9bb commit b5055f3
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 17 deletions.
20 changes: 19 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ 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 @@ -104,6 +108,17 @@ jobs:
# Cannot use -o because of snapshot dependencies.
- run: mvn deploy -s .circleci/settings.xml -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
Expand All @@ -120,4 +135,7 @@ workflows:
only:
- master
requires:
- test-release
- test-release
- docker-build:
name: docker-build
context: global
36 changes: 36 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/.git

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

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### terraform ###
.terraform/
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM eclipse-temurin:17.0.8_7-jdk-alpine as builder

# Cache-mount /root/.m2 to speed up subsequent builds.
# Bind-mount pom.xml, .mvn & mvnw to avoid having to copy it.
RUN --mount=type=bind,source=pom.xml,target=pom.xml \
--mount=type=bind,source=.mvn,target=.mvn \
--mount=type=bind,source=mvnw,target=mvnw \
--mount=type=cache,target=/root/.m2/ \
./mvnw dependency:copy-dependencies

COPY . ./

# Cache-mount /root/.m2 to speed up subsequent builds.
# Bind-mount pom.xml, .mvn & mvnw to avoid having to copy it.
RUN --mount=type=bind,source=pom.xml,target=pom.xml \
--mount=type=bind,source=.mvn,target=.mvn \
--mount=type=bind,source=mvnw,target=mvnw \
--mount=type=cache,target=/root/.m2/ \
env CI=true \
./mvnw install -DskipTests -P prettierSkip

FROM eclipse-temurin:17.0.8_7-jdk-alpine

RUN apk update && apk upgrade && apk add --no-cache \
tini

RUN addgroup appuser && adduser --disabled-password appuser --ingroup appuser
USER appuser

WORKDIR /home/appuser

RUN chown -R appuser:appuser /home/appuser
USER appuser

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

CMD [ "/sbin/tini", "--", "java", "-jar", "lamassu.jar" ]
16 changes: 0 additions & 16 deletions docker-compose/Dockerfile.example

This file was deleted.

16 changes: 16 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

<prettier-java.version>2.1.0</prettier-java.version>
<prettier-maven-plugin.version>0.20</prettier-maven-plugin.version>
<plugin.prettier.goal>write</plugin.prettier.goal>
</properties>

<distributionManagement>
Expand Down Expand Up @@ -267,5 +268,20 @@
<plugin.prettier.goal>check</plugin.prettier.goal>
</properties>
</profile>
<profile>
<id>prettierSkip</id>
<build>
<plugins>
<plugin>
<groupId>com.hubspot.maven.plugins</groupId>
<artifactId>prettier-maven-plugin</artifactId>
<version>${prettier-maven-plugin.version}</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

0 comments on commit b5055f3

Please sign in to comment.