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

Build container in one shot #954

Merged
merged 7 commits into from
Oct 1, 2023
Merged
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
570 changes: 18 additions & 552 deletions .github/workflows/deploy.yml

Large diffs are not rendered by default.

182 changes: 17 additions & 165 deletions .github/workflows/test-pr build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,168 +69,20 @@ jobs:
- name: Run hadolint against Dockerfiles
run: docker run --rm -i -v "$PWD":/workdir --workdir /workdir --entrypoint hadolint hadolint/hadolint $(find . -type f -iname "Dockerfile*")

deploy_ghcr_nextgen_test:
name: Deploy ACARS Hub Next Gen Base Image
runs-on: ubuntu-latest
steps:
# Check out our code
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0

- name: Get specific changed files
id: changed-files-specific
uses: tj-actions/[email protected]
with:
files: |
Dockerfile.nextgen
.github/workflows/test-pr.yml
rootfs/webapp/requirements.txt

- name: Login to ghcr.io
if: steps.changed-files-specific.outputs.any_changed == 'true'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

# Get metadata from repo
- name: Extract metadata (tags, labels) for Docker
id: meta
if: steps.changed-files-specific.outputs.any_changed == 'true'
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# Set up QEMU for multi-arch builds
- name: Set up QEMU
if: steps.changed-files-specific.outputs.any_changed == 'true'
uses: docker/setup-qemu-action@v3

# Set up buildx for multi platform builds
- name: Set up Docker Buildx
id: buildx
if: steps.changed-files-specific.outputs.any_changed == 'true'
uses: docker/setup-buildx-action@v3

# Build & Push Dockerfile (only push if this action was NOT triggered by a PR)
- name: Build & Push ghcr.io/sdr-enthusiasts/docker-acarshub:nextgen-test
if: steps.changed-files-specific.outputs.any_changed == 'true'
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.nextgen
no-cache: true
platforms: linux/386,linux/amd64,linux/arm/v7,linux/arm/v6,linux/arm64
push: true
tags: ghcr.io/sdr-enthusiasts/docker-acarshub:nextgen-test
labels: ${{ steps.meta.outputs.labels }}

deploy_ghcr_latest_test:
name: Deploy test to GHCR
runs-on: ubuntu-latest
needs:
- acarshub-typescript
- deploy_ghcr_nextgen_test

steps:
# Check out our code
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0

- name: Get specific changed files
id: changed-files-specific
uses: tj-actions/[email protected]
with:
files: |
Dockerfile.nextgen
Dockerfile.acarshub
acarshub-typescript/**
rootfs/**
.github/workflows/test-pr.yml
version

- name: Get status of next file
id: changed-file-nextgen
uses: tj-actions/[email protected]
with:
files: |
Dockerfile.nextgen

- name: Download webapp
if: steps.changed-files-specific.outputs.any_changed == 'true'
uses: actions/download-artifact@v3
with:
name: webapp

- name: Get version
if: steps.changed-files-specific.outputs.any_changed == 'true'
run: |
echo "VERSION=$(sed '1!d' ./version-nextgen)" >> $GITHUB_ENV

# Show version tag
- name: Show version tag
if: steps.changed-files-specific.outputs.any_changed == 'true'
run: |
echo "ACARS Hub Version: ${{ env.VERSION }}"
echo "ACARS Hub Build: ${{ github.run_number }}"

- name: Create ACARS Hub Version file
if: steps.changed-files-specific.outputs.any_changed == 'true'
run: |
echo "${{ env.VERSION }} Build ${{ github.run_number }}" > ./rootfs/version

- name: Create version file
if: steps.changed-files-specific.outputs.any_changed == 'true'
run: |
rm ./rootfs/version
echo "${{ env.VERSION }} Build ${{ github.run_number }}" >> ./rootfs/acarshub-version

- name: Login to ghcr.io
if: steps.changed-files-specific.outputs.any_changed == 'true'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

# Get metadata from repo
- name: Extract metadata (tags, labels) for Docker
id: meta
if: steps.changed-files-specific.outputs.any_changed == 'true'
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# Set up QEMU for multi-arch builds
- name: Set up QEMU
if: steps.changed-files-specific.outputs.any_changed == 'true'
uses: docker/setup-qemu-action@v3

# Set up buildx for multi platform builds
- name: Set up Docker Buildx
id: buildx
if: steps.changed-files-specific.outputs.any_changed == 'true'
uses: docker/setup-buildx-action@v3

- name: Patch Dockerfile if Nextgen was built for this branch
if: steps.changed-file-nextgen.outputs.any_changed == 'true'
run: sed -i "s/^FROM ghcr.io\/sdr-enthusiasts\/docker-acarshub:nextgen/FROM ghcr.io\/sdr-enthusiasts\/docker-acarshub:nextgen-test/g" Dockerfile.acarshub

# Build & Push Dockerfile (only push if this action was NOT triggered by a PR)
- name: Build & Push ghcr.io/sdr-enthusiasts/docker-acarshub:test
if: steps.changed-files-specific.outputs.any_changed == 'true'
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.acarshub
no-cache: true
platforms: linux/386,linux/amd64,linux/arm/v7,linux/arm/v6,linux/arm64
push: true
tags: ghcr.io/sdr-enthusiasts/docker-acarshub:test
#tags: ghcr.io/sdr-enthusiasts/docker-acarshub:test-${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
labels: ${{ steps.meta.outputs.labels }}
deploy:
name: Deploy
uses: sdr-enthusiasts/common-github-workflows/.github/workflows/build_and_push_image.yml@main
with:
push_enabled: false
push_destinations: ghcr.io
ghcr_repo_owner: ${{ github.repository_owner }}
ghcr_repo: ${{ github.repository }}
# set build_latest to true if github.event.inputs.use_test_image is false
build_latest: true
build_baseimage_test: false
# only build the entire stack if we are not using the test image
build_version_specific: false
build_platform_specific: false
build_nohealthcheck: false
secrets:
ghcr_token: ${{ secrets.GITHUB_TOKEN }}
120 changes: 120 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
FROM node:slim AS acarshub-typescript-builder
# pushd/popd
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

ENV DOCKER_BUILD="true"

#hadolint ignore=DL3008
RUN set -xe && \
apt-get update && \
apt-get install -y --no-install-recommends make python3 g++ && \
rm -rf /src/* /tmp/* /var/lib/apt/lists/*

COPY acarshub-typescript/package.json /acarshub-typescript/package.json
COPY acarshub-typescript/package-lock.json /acarshub-typescript/package-lock.json

RUN set -xe && \
pushd /acarshub-typescript && \
npm install

COPY acarshub-typescript/ /acarshub-typescript/

RUN set -xe && \
pushd /acarshub-typescript && \
mkdir -p /webapp/static/images && \
mkdir -p /webapp/static/js && \
mkdir -p /webapp/static/sounds && \
mkdir -p /webapp/templates && \
npm run build && \
cp -r ./dist/static/images /webapp/static/ && \
cp -r ./dist/static/sounds /webapp/static/ && \
cp -r ./dist/static/js /webapp/static/ && \
mv ./dist/static/index.html /webapp/templates/

FROM ghcr.io/sdr-enthusiasts/docker-baseimage:python
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

COPY rootfs/webapp/requirements.txt /src/requirements.txt

# hadolint ignore=DL3008,SC2086,DL3042,DL3013,SC1091
RUN set -x && \
TEMP_PACKAGES=() && \
KEPT_PACKAGES=() && \
# Required for building multiple packages.
TEMP_PACKAGES+=(build-essential) && \
TEMP_PACKAGES+=(pkg-config) && \
TEMP_PACKAGES+=(cmake) && \
TEMP_PACKAGES+=(automake) && \
TEMP_PACKAGES+=(autoconf) && \
TEMP_PACKAGES+=(git) && \
# Packages for nginx+python
KEPT_PACKAGES+=(nginx-light) && \
TEMP_PACKAGES+=(python3-dev) && \
KEPT_PACKAGES+=(python3-cryptography) && \
# stats
KEPT_PACKAGES+=(rrdtool) && \
TEMP_PACKAGES+=(librrd-dev) && \
apt-get update && \
apt-get install -y --no-install-recommends \
"${KEPT_PACKAGES[@]}" \
"${TEMP_PACKAGES[@]}"\
&& \
pushd /src/ && \
python3 -m pip install --no-cache-dir --break-system-packages \
-r /src/requirements.txt \
&& \
# Fix for Eventlet issues
apt-get \
-o Dpkg::Options::='--force-confmiss' \
install --reinstall --no-install-recommends -y \
netbase \
&& \
popd && \
# Clean up
apt-get remove -y "${TEMP_PACKAGES[@]}" && \
apt-get autoremove -y && \
rm -rf /src/* /tmp/* /var/lib/apt/lists/* && \
rm -rf /root/.cargo

COPY --from=acarshub-typescript-builder /webapp/static/ /webapp/static/
COPY --from=acarshub-typescript-builder /webapp/templates/ /webapp/templates/

RUN set -x && \
mkdir -p /run/acars && \
# grab the ground stations and other data from airframes
mkdir -p /webapp/data/ && \
# Download the airframes Ground Station and ACARS Label data
pushd /webapp/data/ && \
curl -O https://raw.githubusercontent.com/airframesio/data/master/json/vdl/ground-stations.json&& \
curl -O https://raw.githubusercontent.com/airframesio/data/master/json/acars/metadata.json && \
# Clean up
rm -rf /src/* /tmp/* /var/lib/apt/lists/*

COPY rootfs/ /
COPY version-nextgen /acarshub-version

EXPOSE 80
EXPOSE 5550
EXPOSE 5555
EXPOSE 15550
EXPOSE 15555

ENV FEED="" \
ENABLE_ACARS="false" \
ENABLE_VDLM="false" \
ENABLE_ADSB="false" \
ENABLE_WEB="true" \
MIN_LOG_LEVEL=3 \
QUIET_MESSAGES="true" \
DB_SAVEALL="true" \
ENABLE_RANGE_RINGS="true" \
ADSB_URL="http://tar1090/data/aircraft.json"


# Add healthcheck
HEALTHCHECK --start-period=3600s --interval=600s CMD /scripts/healthcheck.sh

ARG BUILD_EXTRA="Build git"
# append BUILD_EXTRA to the only line in /acarshub-version
RUN set -x && \
echo "$(cat /acarshub-version) ${BUILD_EXTRA}" > /acarshub-version
40 changes: 0 additions & 40 deletions Dockerfile.acarshub

This file was deleted.

26 changes: 0 additions & 26 deletions Dockerfile.acarshub-typescript

This file was deleted.

Loading