Skip to content

Commit fef95b3

Browse files
authored
Merge pull request #26 from michaelconan/fix/nonroot
Fix/nonroot
2 parents 1cfaf51 + 2497680 commit fef95b3

18 files changed

+216
-154
lines changed

.devcontainer/Dockerfile

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
FROM python:3.12-slim
22

3+
# User and Group identifiers
4+
ARG UID=1000
5+
ARG GID=1000
6+
7+
# Add local bin to PATH
8+
ENV PATH="/home/vscode/.local/bin:${PATH}"
9+
310
# Install git and other dependencies
411
RUN apt-get update && \
5-
apt-get install -y --no-install-recommends git && \
12+
apt-get install -y --no-install-recommends git sudo && \
613
apt-get clean && \
7-
rm -rf /var/lib/apt/lists/*
14+
rm -rf /var/lib/apt/lists/*
15+
16+
# Create and run as non-root user
17+
RUN addgroup --gid $GID vscode && \
18+
adduser --uid $UID --gid $GID vscode
19+
20+
# Allow the non-root user to run sudo without a password
21+
RUN echo "vscode ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/vscode \
22+
&& chmod 0440 /etc/sudoers.d/vscode
23+
24+
USER vscode

.devcontainer/devcontainer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
22
// README at: https://github.com/devcontainers/templates/tree/main/src/postgres
33
{
4-
"name": "Python 3 & PostgreSQL",
4+
"name": "Local Airflow",
55
"dockerComposeFile": "docker-compose.yml",
66
"service": "app",
77
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
@@ -26,9 +26,9 @@
2626
5432
2727
],
2828
// Use 'postCreateCommand' to run commands after the container is created.
29-
"postCreateCommand": "chmod -R +x script/* && script/setup"
29+
"postCreateCommand": "sudo chown -R vscode:vscode $PWD && chmod -R 777 script/* && script/setup",
3030
// Configure tool-specific properties.
3131
// "customizations": {},
3232
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
33-
// "remoteUser": "root"
33+
"remoteUser": "vscode"
3434
}

.flake8

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
max-line-length = 100

.github/workflows/ci.yml

+16-9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ env:
1414
jobs:
1515
test:
1616
runs-on: ubuntu-latest
17+
permissions:
18+
packages: write
19+
contents: read
1720
env:
1821
CI: true
1922

@@ -27,7 +30,7 @@ jobs:
2730
echo "$AIRFLOW_CONNECTIONS" > ${{ env.CONNECTIONS_FILE }}
2831
2932
- name: Login to GitHub Container Registry
30-
uses: docker/login-action@v2
33+
uses: docker/login-action@v2
3134
with:
3235
registry: ${{ env.REGISTRY }}
3336
username: ${{ github.actor }}
@@ -40,20 +43,24 @@ jobs:
4043
cacheFrom: ${{ env.IMAGE_NAME }}
4144
push: always
4245

43-
- name: Build and run Dev Container task
46+
- name: Build container and run pre-commit format and lint
4447
uses: devcontainers/[email protected]
4548
with:
46-
# Devcontainer image
4749
imageName: ${{ env.IMAGE_NAME }}
48-
# Run setup, validation and tests in dev container
50+
cacheFrom: ${{ env.IMAGE_NAME }}
51+
# Run pre-commit checks
4952
runCmd: |
50-
# Run setup steps
51-
script/setup
52-
# Run pre-commit checks
5353
pre-commit run --all-files --verbose --show-diff-on-failure
54-
# Run tests (which now have access to connections)
54+
55+
- name: Build container and run unit tests
56+
uses: devcontainers/[email protected]
57+
with:
58+
imageName: ${{ env.IMAGE_NAME }}
59+
cacheFrom: ${{ env.IMAGE_NAME }}
60+
# Run unit tests
61+
runCmd: |
5562
script/test
5663
5764
- name: Cleanup Files
5865
run: |
59-
rm ${{ env.CONNECTIONS_FILE }}
66+
rm -f ${{ env.CONNECTIONS_FILE }}

.pre-commit-config.yaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ repos:
1313
rev: v3.1.0
1414
hooks:
1515
- id: add-trailing-comma
16-
- repo: https://github.com/psf/black
17-
rev: 24.10.10
16+
- repo: https://github.com/psf/black-pre-commit-mirror
17+
rev: 24.8.0
1818
hooks:
1919
- id: black
20+
language_version: python3.12
2021
- repo: https://github.com/PyCQA/flake8
2122
rev: 6.1.0
2223
hooks:

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ graph TB
5252

5353
1. [Alembic](https://alembic.sqlalchemy.org/en/latest/) database migrations for raw tables which should generally match the schema of the source system, run via [Airflow provider package](https://pypi.org/project/airflow-provider-alembic/)
5454
2. [Airflow](https://airflow.apache.org/) to orchestrate data loading scripts and additional automated workflows
55-
3. [DBT core](https://docs.getdbt.com/) to define data models and transformations, again orchestrated by Airflow (via CLI / `BashOperator`)
55+
3. [DBT core](https://docs.getdbt.com/) to define data models and transformations, again orchestrated by Airflow (via CLI / `BashOperator`)
5656

5757

5858
## Setup
@@ -78,7 +78,7 @@ To run Airflow on a single instance, I used Honcho to run multiple processes via
7878
5. Set startup command to use the `startup.txt` file
7979
6. Run database migrations (`airflow db migrate`) and user setup (`airflow users create`) as one-off admin process, Procfile just for main processes
8080
- Reference [quick start](https://airflow.apache.org/docs/apache-airflow/stable/start.html) for guidance on this setup process
81-
- It may be necessary to run these via startup command to get the app to launch
81+
- It may be necessary to run these via startup command to get the app to launch
8282

8383
### Automated Deployment
8484

0 commit comments

Comments
 (0)