Skip to content
name: Build Docker Image (Native)
on:
workflow_call:
inputs:
version:
required: false
type: string
default: '21'
distribution:
required: false
type: string
default: 'graalvm'
target_ref:
required: false
type: string
default: 'refs/heads/main'
image_file:
required: false
type: string
default: image.yaml
e2e_test:
required: false
type: boolean
default: false
test_url_1:
required: false
type: string
default: ""
test_url_2:
required: false
type: string
default: ""
download_target:
required: false
type: boolean
default: true
image_tag_suffix:
required: false
type: string
default: ""
use_pre_built_artifact:
required: false
type: boolean
default: false
pre_built_artifact_name:
required: false
type: string
default: ""
pre_built_artifact_path:
required: false
type: string
default: ""
runs-on:
required: false
type: string
default: '["ubuntu-latest"]'
jobs:
build:
if: github.ref == inputs.target_ref
runs-on: ${{fromJSON(inputs.runs-on)}}
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v2
- uses: graalvm/setup-graalvm@v1
if: ${{ !inputs.use_pre_built_artifact }}
with:
java-version: ${{ inputs.version }}
distribution: ${{ inputs.distribution }}
cache: 'maven'
- name: Download build artifacts
if: ${{ !inputs.use_pre_built_artifact && inputs.download_target }}
uses: actions/download-artifact@v2
with:
name: build-artifacts
path: target
- name: Set version
uses: making/workflows/.github/actions/set-version-with-sha
- name: native image
if: ${{ !inputs.use_pre_built_artifact }}
run: ./mvnw -V --no-transfer-progress -Pnative native:compile -DskipTests
- name: Download pre-build artifact
if: inputs.use_pre_built_artifact
uses: actions/download-artifact@v2
with:
name: ${{ inputs.pre_built_artifact_name }}
path: ${{ inputs.pre_built_artifact_path }}
- name: Move downloaded file
if: inputs.use_pre_built_artifact
run: |
ls -la ${{ inputs.pre_built_artifact_path }}
mkdir -p target
mv ${{ inputs.pre_built_artifact_path }}/* target/${GITHUB_REPOSITORY#${GITHUB_REPOSITORY_OWNER}/}
chmod +x target/${GITHUB_REPOSITORY#${GITHUB_REPOSITORY_OWNER}/}
ls -la target
file target/${GITHUB_REPOSITORY#${GITHUB_REPOSITORY_OWNER}/}
- name: Prepare wait.sh
if: inputs.e2e_test
run: |
wget -q https://github.com/making/workflows/raw/main/wait.sh
chmod +x wait.sh
- name: E2E Test
if: inputs.e2e_test
env:
TEST_URL_1: ${{ inputs.test_url_1 }}
TEST_URL_2: ${{ inputs.test_url_2 }}
run: |
./target/${GITHUB_REPOSITORY#${GITHUB_REPOSITORY_OWNER}/} \
--server.port=8080 \
--management.otlp.tracing.endpoint=https://httpbin.org/post \
--management.otlp.logging.endpoint=https://httpbin.org/post \
& ./wait.sh
if [ -n "${TEST_URL_1}" ]; then
curl --fail --show-error --silent "${TEST_URL_1}"
fi
if [ -n "${TEST_URL_2}" ]; then
curl --fail --show-error --silent "${TEST_URL_2}"
fi
pkill -KILL ${GITHUB_REPOSITORY#${GITHUB_REPOSITORY_OWNER}/} || true
- name: Install Pack
uses: buildpacks/github-actions/setup-pack@v5.7.3
- name: Pack Build
run: |
mkdir -p pack
mv ./target/${GITHUB_REPOSITORY#${GITHUB_REPOSITORY_OWNER}/} ./pack
cat <<EOF > pack/Procfile
web: ./${GITHUB_REPOSITORY#${GITHUB_REPOSITORY_OWNER}/}
EOF
pack build ghcr.io/${{ github.repository }}:native${{ inputs.image_tag_suffix }}_${GITHUB_SHA} \
--env BP_OCI_SOURCE=https://github.com/${GITHUB_REPOSITORY} \
--env BP_OCI_REVISION=${GITHUB_SHA} \
--gid 1002 \
--builder paketobuildpacks/builder-jammy-buildpackless-tiny \
--buildpack gcr.io/paketo-buildpacks/image-labels \
--buildpack gcr.io/paketo-buildpacks/procfile \
--path pack
- name: Login to GitHub Container Registry
uses: docker/#-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: docker push
run: |
docker push ghcr.io/${{ github.repository }}:native${{ inputs.image_tag_suffix }}_${GITHUB_SHA}
docker tag ghcr.io/${{ github.repository }}:native${{ inputs.image_tag_suffix }}_${GITHUB_SHA} ghcr.io/${{ github.repository }}:native${{ inputs.image_tag_suffix }}
docker push ghcr.io/${{ github.repository }}:native${{ inputs.image_tag_suffix }}
- name: Generate digest
run: |
cat <<EOF > ${{ inputs.image_file }}
image: $(docker inspect --format='{{index .RepoDigests 0}}' ghcr.io/${{ github.repository }}:native${{ inputs.image_tag_suffix }}_${GITHUB_SHA})
git_revision: ${GITHUB_SHA}
EOF
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: image
path: ${{ inputs.image_file }}