Skip to content

Commit

Permalink
Add Codespaces support (apache#22082)
Browse files Browse the repository at this point in the history
* Add Codespaces support

Codespaces is (soon to be GA) feature that allows to start
development environment on a virtual machine directly from the
GitHub UI or from VSCode connected with GitHub account.

This PR adds configuration that allows to start codespaces
environment (based on Breeze's docker compose environment)
in the basic form that allows the users to run basic unit
tests.

It does not replace Breeze/CI but for most users who want
to just run a few tests, make sure that all dependencies
and plugins are installed so that the users can get the
VSCode autocomplete and execution of the tests possible.

This is a great way to begin your journey with Airflow - while
the Codespace machines are not very powerful and the integration
tests might require more resources, the "no-setup"
environment and no need to have powerful machine is great
for contributors who cannot afford powerful development
workstations.

* Update CONTRIBUTING.rst

Co-authored-by: Ephraim Anierobi <[email protected]>

* Update scripts/ci/libraries/_build_images.sh

Co-authored-by: Ephraim Anierobi <[email protected]>

* Update CONTRIBUTING.rst

Co-authored-by: Ephraim Anierobi <[email protected]>
  • Loading branch information
potiuk and ephraimbuddy authored Mar 9, 2022
1 parent b1fdcdf commit 05f3a30
Show file tree
Hide file tree
Showing 58 changed files with 293 additions and 134 deletions.
24 changes: 24 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "Apache Airflow",
"dockerComposeFile": [
"../scripts/ci/docker-compose/devcontainer.yml",
"../scripts/ci/docker-compose/local.yml",
"../scripts/ci/docker-compose/backend-postgres.yml",
"../scripts/ci/docker-compose/devcontainer-postgres.yml"
],
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"mtxr.sqltools",
"mtxr.sqltools-driver-pg",
"rogalmic.bash-debug",
"ms-azuretools.vscode-docker",
"dbaeumer.vscode-eslint",
"ecmel.vscode-html-css",
"timonwong.shellcheck",
"redhat.vscode-yaml",
"rogalmic.bash-debug"
],
"service": "airflow",
"forwardPorts": [8080,5555,5432,6379]
}
8 changes: 1 addition & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -708,13 +708,7 @@ repos:
language: system
entry: ./scripts/ci/pre_commit/pre_commit_mypy.sh --namespace-packages
files: \.py$
exclude: ^provider_packages|^chart|^docs|^airflow/_vendor/
require_serial: true
- id: mypy
name: Run mypy for helm chart tests
language: system
entry: ./scripts/ci/pre_commit/pre_commit_mypy.sh
files: ^chart/.*\.py$
exclude: ^provider_packages|^docs|^airflow/_vendor/
require_serial: true
- id: mypy
name: Run mypy for /docs/ folder
Expand Down
65 changes: 38 additions & 27 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,24 @@ From the `apache/airflow <https://github.com/apache/airflow>`_ repo,
Step 2: Configure Your Environment
----------------------------------

You can use either a local virtual env or a Docker-based env. The differences
between the two are explained `here <https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#development-environments>`__.
You can use several development environments for Airflow. If you prefer to have development environments
on your local machine, you might choose Local Virtualenv, or dockerized Breeze environment, however we
also have support for popular remote development environments: GitHub Codespaces and GitPodify.
You can see the differences between the various environments
`here <https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#development-environments>`__.


The local env's instructions can be found in full in the `LOCAL_VIRTUALENV.rst`_ file.
The local env instructions can be found in full in the `LOCAL_VIRTUALENV.rst`_ file.

.. _LOCAL_VIRTUALENV.rst:
https://github.com/apache/airflow/blob/main/LOCAL_VIRTUALENV.rst
The Docker env is here to maintain a consistent and common development environment so that you can replicate CI failures locally and work on solving them locally rather by pushing to CI.

The Breeze Docker Compose env is to maintain a consistent and common development environment so that you
can replicate CI failures locally and work on solving them locally rather by pushing to CI.

The Breeze instructions can be found in full in the `BREEZE.rst`_ file.

.. _BREEZE.rst:
https://github.com/apache/airflow/blob/main/BREEZE.rst

You can configure the Docker-based Breeze development environment as follows:

Expand Down Expand Up @@ -469,28 +478,30 @@ develop Apache Airflow:
- `Breeze Docker-based development environment <#breeze-development-environment>`_ that provides
an end-to-end CI solution with all software dependencies covered.

The table below summarizes differences between the two environments:


========================= ================================ =====================================
**Property** **Local virtualenv** **Breeze environment**
========================= ================================ =====================================
Test coverage - (-) unit tests only - (+) integration and unit tests
------------------------- -------------------------------- -------------------------------------
Setup - (+) automated with breeze cmd - (+) automated with breeze cmd
------------------------- -------------------------------- -------------------------------------
Installation difficulty - (-) depends on the OS setup - (+) works whenever Docker works
------------------------- -------------------------------- -------------------------------------
Team synchronization - (-) difficult to achieve - (+) reproducible within team
------------------------- -------------------------------- -------------------------------------
Reproducing CI failures - (-) not possible in many cases - (+) fully reproducible
------------------------- -------------------------------- -------------------------------------
Ability to update - (-) requires manual updates - (+) automated update via breeze cmd
------------------------- -------------------------------- -------------------------------------
Disk space and CPU usage - (+) relatively lightweight - (-) uses GBs of disk and many CPUs
------------------------- -------------------------------- -------------------------------------
IDE integration - (+) straightforward - (-) via remote debugging only
========================= ================================ =====================================
The table below summarizes differences between the environments:


========================= ================================ ===================================== ========================================
**Property** **Local virtualenv** **Breeze environment** **GitHub Codespaces**
========================= ================================ ===================================== ========================================
Dev machine needed - (-) You need a dev PC - (-) You need a dev PC (+) Works with remote setup
------------------------- -------------------------------- ------------------------------------- ----------------------------------------
Test coverage - (-) unit tests only - (+) integration and unit tests (*/-) integration tests (extra config)
------------------------- -------------------------------- ------------------------------------- ----------------------------------------
Setup - (+) automated with breeze cmd - (+) automated with breeze cmd (+) automated with VSCode
------------------------- -------------------------------- ------------------------------------- ----------------------------------------
Installation difficulty - (-) depends on the OS setup - (+) works whenever Docker works (+) works in a modern browser/VSCode
------------------------- -------------------------------- ------------------------------------- ----------------------------------------
Team synchronization - (-) difficult to achieve - (+) reproducible within team (+) reproducible within team
------------------------- -------------------------------- ------------------------------------- ----------------------------------------
Reproducing CI failures - (-) not possible in many cases - (+) fully reproducible (+) reproduce CI failures
------------------------- -------------------------------- ------------------------------------- ----------------------------------------
Ability to update - (-) requires manual updates - (+) automated update via breeze cmd (+/-) can be rebuild on demand
------------------------- -------------------------------- ------------------------------------- ----------------------------------------
Disk space and CPU usage - (+) relatively lightweight - (-) uses GBs of disk and many CPUs (-) integration tests (extra config)
------------------------- -------------------------------- ------------------------------------- ----------------------------------------
IDE integration - (+) straightforward - (-) via remote debugging only (-) integration tests (extra config)
========================= ================================ ===================================== ----------------------------------------

Typically, you are recommended to use both of these environments depending on your needs.
Expand Down
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ FROM ${PYTHON_BASE_IMAGE} as airflow-build-image
SHELL ["/bin/bash", "-o", "pipefail", "-o", "errexit", "-o", "nounset", "-o", "nolog", "-c"]

ARG PYTHON_BASE_IMAGE

ENV PYTHON_BASE_IMAGE=${PYTHON_BASE_IMAGE} \
DEBIAN_FRONTEND=noninteractive LANGUAGE=C.UTF-8 LANG=C.UTF-8 LC_ALL=C.UTF-8 \
LC_CTYPE=C.UTF-8 LC_MESSAGES=C.UTF-8
Expand Down
4 changes: 2 additions & 2 deletions TESTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ Helm Unit Tests

On the Airflow Project, we have decided to stick with pythonic testing for our Helm chart. This makes our chart
easier to test, easier to modify, and able to run with the same testing infrastructure. To add Helm unit tests
go to the ``chart/tests`` directory and add your unit test by creating a class that extends ``unittest.TestCase``
add them in ``tests/charts``.

.. code-block:: python
Expand All @@ -249,7 +249,7 @@ Example test here:

.. code-block:: python
from .helm_template_generator import render_chart, render_k8s_object
from tests.charts.helm_template_generator import render_chart, render_k8s_object
git_sync_basic = """
dags:
Expand Down
25 changes: 25 additions & 0 deletions scripts/ci/docker-compose/devcontainer-mysql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
---
version: "3.7"
services:
mysql:
image: mysql:8.0
ports:
- "3306:3306"
volumes:
mysql-db-volume:
25 changes: 25 additions & 0 deletions scripts/ci/docker-compose/devcontainer-postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
---
version: "3.7"
services:
postgres:
image: postgres:10
ports:
- "5432:5432"
volumes:
postgres-db-volume:
51 changes: 51 additions & 0 deletions scripts/ci/docker-compose/devcontainer.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
HOME=
AIRFLOW_CI_IMAGE="ghcr.io/apache/airflow/main/ci/python3.7:latest"
PYTHON_MAJOR_MINOR_VERSION="3.7"
AIRFLOW_EXTRAS=
BREEZE="true"
CI="false"
CI_BUILD_ID=
CI_JOB_ID=
CI_EVENT_TYPE=
CI_TARGET_REPO=
CI_TARGET_BRANCH=
COMMIT_SHA=
DB_RESET="false"
DEFAULT_BRANCH="main"
DEFAULT_CONSTRAINTS_BRANCH="constraints-main"
ENABLED_INTEGRATIONS=
ENABLED_SYSTEMS=
ENABLE_TEST_COVERAGE="false"
GITHUB_ACTIONS="false"
GITHUB_REGISTRY_PULL_IMAGE_TAG=""
HOST_USER_ID=
HOST_GROUP_ID=
HOST_OS="Linux"
INIT_SCRIPT_FILE="init.sh"
INSTALL_AIRFLOW_VERSION=
GENERATE_CONSTRAINTS_MODE=
INSTALL_PROVIDERS_FROM_SOURCES=
USE_AIRFLOW_VERSION=
USE_PACKAGES_FROM_DIST=
ISSUE_ID=
LOAD_DEFAULT_CONNECTIONS=
LOAD_EXAMPLES=
MYSQL_VERSION=5.7
NUM_RUNS=
PACKAGE_FORMAT=
POSTGRES_VERSION=10
PRINT_INFO_FROM_SCRIPTS="false"
PYTHONDONTWRITEBYTECODE="true"
RUN_TESTS="false"
LIST_OF_INTEGRATION_TESTS_TO_RUN=""
RUN_SYSTEM_TESTS=""
START_AIRFLOW="false"
SKIP_TWINE_CHECK="false"
SKIP_SSH_SETUP="true"
TEST_TYPE=
UPGRADE_TO_NEWER_DEPENDENCIES="false"
VERBOSE="false"
VERBOSE_COMMANDS="false"
VERSION_SUFFIX_FOR_PYPI=
VERSION_SUFFIX_FOR_SVN=
WHEEL_VERSION=0.36.2
33 changes: 33 additions & 0 deletions scripts/ci/docker-compose/devcontainer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
---
version: "3.7"
services:
airflow:
image: ghcr.io/apache/airflow/main/ci/python3.7
env_file: devcontainer.env
ports:
- "22:22"
- "8080:8080"
- "5555:5555"
- "6379:6379"
cap_add:
- SYS_PTRACE
volumes:
# Pass docker to inside of the container so that Kind and Moto tests can use it.
- /var/run/docker.sock:/var/run/docker.sock
- /dev/urandom:/dev/random # Required to get non-blocking entropy source
2 changes: 0 additions & 2 deletions scripts/ci/docker-compose/local-all-sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,3 @@ services:
- ../../../.inputrc:/root/.inputrc:cached
- ../../../tmp:/tmp:cached
- ../../../:/opt/airflow:cached
ports:
- "${WEBSERVER_HOST_PORT}:8080"
2 changes: 0 additions & 2 deletions scripts/ci/docker-compose/local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,3 @@ services:
- ../../../chart:/opt/airflow/chart:cached
- ../../../metastore_browser:/opt/airflow/metastore_browser:cached
# END automatically generated volumes from LOCAL_MOUNTS in _local_mounts.sh
ports:
- "${WEBSERVER_HOST_PORT}:8080"
3 changes: 3 additions & 0 deletions scripts/ci/libraries/_initialization.sh
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,9 @@ function initialization::initialize_image_build_variables() {
SKIP_TWINE_CHECK=${SKIP_TWINE_CHECK:=""}
export SKIP_TWINE_CHECK

SKIP_SSH_SETUP=${SKIP_SSH_SETUP:="false"}
export SKIP_SSH_SETUP

export INSTALLED_EXTRAS="async,amazon,celery,cncf.kubernetes,docker,dask,elasticsearch,ftp,grpc,hashicorp,http,imap,ldap,google,microsoft.azure,mysql,postgres,redis,sendgrid,sftp,slack,ssh,statsd,virtualenv"

AIRFLOW_PIP_VERSION=${AIRFLOW_PIP_VERSION:="22.0.4"}
Expand Down
39 changes: 21 additions & 18 deletions scripts/in_container/entrypoint_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -157,24 +157,26 @@ mkdir -p /usr/lib/google-cloud-sdk/bin
touch /usr/lib/google-cloud-sdk/bin/gcloud
ln -s -f /usr/bin/gcloud /usr/lib/google-cloud-sdk/bin/gcloud

# Set up ssh keys
echo 'yes' | ssh-keygen -t rsa -C [email protected] -m PEM -P '' -f ~/.ssh/id_rsa \
>"${AIRFLOW_HOME}/logs/ssh-keygen.log" 2>&1

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
ln -s -f ~/.ssh/authorized_keys ~/.ssh/authorized_keys2
chmod 600 ~/.ssh/*

# SSH Service
sudo service ssh restart >/dev/null 2>&1

# Sometimes the server is not quick enough to load the keys!
while [[ $(ssh-keyscan -H localhost 2>/dev/null | wc -l) != "3" ]] ; do
echo "Not all keys yet loaded by the server"
sleep 0.05
done
if [[ ${SKIP_SSH_SETUP="false"} == "false" ]]; then
# Set up ssh keys
echo 'yes' | ssh-keygen -t rsa -C [email protected] -m PEM -P '' -f ~/.ssh/id_rsa \
>"${AIRFLOW_HOME}/logs/ssh-keygen.log" 2>&1

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
ln -s -f ~/.ssh/authorized_keys ~/.ssh/authorized_keys2
chmod 600 ~/.ssh/*

# SSH Service
sudo service ssh restart >/dev/null 2>&1

# Sometimes the server is not quick enough to load the keys!
while [[ $(ssh-keyscan -H localhost 2>/dev/null | wc -l) != "3" ]] ; do
echo "Not all keys yet loaded by the server"
sleep 0.05
done

ssh-keyscan -H localhost >> ~/.ssh/known_hosts 2>/dev/null
ssh-keyscan -H localhost >> ~/.ssh/known_hosts 2>/dev/null
fi

# shellcheck source=scripts/in_container/configure_environment.sh
. "${IN_CONTAINER_DIR}/configure_environment.sh"
Expand Down Expand Up @@ -283,11 +285,12 @@ else
"tests/utils"
)
WWW_TESTS=("tests/www")
HELM_CHART_TESTS=("chart/tests")
HELM_CHART_TESTS=("tests/charts")
ALL_TESTS=("tests")
ALL_PRESELECTED_TESTS=(
"${CLI_TESTS[@]}"
"${API_TESTS[@]}"
"${HELM_CHART_TESTS[@]}"
"${PROVIDERS_TESTS[@]}"
"${CORE_TESTS[@]}"
"${ALWAYS_TESTS[@]}"
Expand Down
File renamed without changes.
Loading

0 comments on commit 05f3a30

Please sign in to comment.