Skip to content

Instantly share code, notes, and snippets.

@misTrasteos
Last active February 18, 2021 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save misTrasteos/4f791cf1ef23506cf1d1cd0fc5db68f1 to your computer and use it in GitHub Desktop.
Save misTrasteos/4f791cf1ef23506cf1d1cd0fc5db68f1 to your computer and use it in GitHub Desktop.
Trying to build my own github actions agent

This is an attempt to to build my own Github actions virtual environments, specifically for Java builds.

how to build

docker build -t runner-java:0.0.1-SNAPSHOT .

how to use

docker run -it --rm runner-java:0.0.1-SNAPSHOT bash

** how to build your mvn project ** mount your source code directory into a folder (-v option) and change working directory of the container into it (-w option)

docker run -it --rm -v $(pwd)/mvn-docker/settings.env1.xml:/root/.m2/settings.xml -v $(pwd)/mvn-docker/repository:/root/.m2/repository -v $(pwd):/src -w /src runner-java:0.0.1-SNAPSHOT mvn clean package

repository points to a directory in your local which can act as a reusable local repository for all your builds. You can also use a volume, or even mount ~/.m2/repository from your local maven installation.

settings.env1.xml this is a PoC of having more than one settings.xml file. For instance, each one of them can point to different distributionManagement repositories, or even different auth options.

In this example, both files are placed in a mvn-docker directorio. You can place them where ever suits you.

# DISCLAIMER, this is not the best way to build a Docker Image. It is still WIP, so I find this way easier to modify.
FROM ubuntu:20.04
ARG JAVA_VERSION=adoptopenjdk-8-hotspot
ARG MAVEN_VERSION=3.6.3
# general stuff
RUN apt-get update
RUN apt-get install wget -y
RUN apt-get install apt-transport-https -y
RUN apt-get install gnupg -y
RUN apt-get install software-properties-common -y
RUN apt-get install rpm -y
# Java
# https://adoptopenjdk.net/installation.html
# https://github.com/actions/virtual-environments/blob/main/images/linux/scripts/installers/java-tools.sh
RUN wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | apt-key add -
RUN echo "deb https://adoptopenjdk.jfrog.io/adoptopenjdk/deb focal main" | tee /etc/apt/sources.list.d/adoptopenjdk.list
RUN apt-get update
RUN apt-get install ${JAVA_VERSION} -y
RUN echo "JAVA_HOME=/usr/lib/jvm/${JAVA_VERSION}-amd64" | tee -a /etc/environment
# Apache Maven
# https://github.com/actions/virtual-environments/blob/main/images/linux/scripts/installers/java-tools.sh
RUN wget -q https://www-eu.apache.org/dist/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz
RUN ls -l apache-maven-${MAVEN_VERSION}-bin.tar.gz
RUN tar -zxf apache-maven-${MAVEN_VERSION}-bin.tar.gz -C /usr/share
RUN rm apache-maven-${MAVEN_VERSION}-bin.tar.gz
RUN ln -s /usr/share/apache-maven-${MAVEN_VERSION}/bin/mvn /usr/bin/mvn
# Git
# https://github.com/actions/virtual-environments/blob/main/images/linux/scripts/installers/git.sh
RUN add-apt-repository ppa:git-core/ppa -y
RUN apt-get update
RUN apt-get install git -y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment