Skip to content

Commit c6a15dd

Browse files
authored
[CIVIS-9315] Fix apt-get and update AWS CLI (#97)
This fixes `apt-get` by updating the base image. Also: * Updates the AWS CLI to v2. * Makes `generate-requirements-full.sh` run in a docker container to ensure the environment matches. * Updates the code build config to use a FIPS URL (see, e.g., civisanalytics/datascience-r#52) and to run builds for branches. * Updates the major version to 8 since the AWS CLI major version changed. * Addresses https://github.com/civisanalytics/datascience-python/security/dependabot/10
1 parent 3271eb0 commit c6a15dd

File tree

10 files changed

+89
-45
lines changed

10 files changed

+89
-45
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
- checkout
88
- setup_remote_docker
99
- run:
10-
name: Build container
10+
name: Build image
1111
command: docker build --target test -t ds-python .
1212
- run:
1313
name: Verify build completed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ Version number changes (major.minor.micro) in this package denote the following:
99

1010
## Unreleased
1111

12+
## [8.0.0]
13+
- Core dependencies updated to latest versions:
14+
* awscli 1.33.9 -> 2.17.37
15+
- Python version updated to v3.12.5
16+
- Fixes apt-get for debian package installations
17+
1218
## [7.3.0]
1319
- Core dependencies updated to latest versions:
1420
* awscli 1.32.112 -> 1.33.9

Dockerfile

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
FROM python:3.12.4-slim AS production
1+
ARG PLATFORM=linux/x86_64
2+
ARG BASE_IMAGE=python:3.12.5-slim
23

3-
LABEL maintainer = [email protected]
4+
# This is the primary build target used for the production image
5+
FROM --platform=$PLATFORM $BASE_IMAGE AS production
6+
7+
# Disable pip warnings https://stackoverflow.com/a/72551258
8+
ENV PIP_ROOT_USER_ACTION=ignore
9+
10+
411

512
RUN DEBIAN_FRONTEND=noninteractive apt-get update -y --no-install-recommends && \
613
apt-get install -y --no-install-recommends locales && \
@@ -19,7 +26,9 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update -y --no-install-recommends &&
1926
libxrender1 \
2027
wget \
2128
ca-certificates \
22-
curl && \
29+
curl \
30+
mandoc \
31+
unzip && \
2332
apt-get clean -y && \
2433
rm -rf /var/lib/apt/lists/*
2534

@@ -34,14 +43,28 @@ RUN pip install --progress-bar off --no-cache-dir -r requirements-full.txt && \
3443
# https://github.com/joblib/joblib/blob/0.11/joblib/parallel.py#L328L342
3544
ENV JOBLIB_TEMP_FOLDER=/tmp
3645

37-
ENV VERSION=7.3.0 \
38-
VERSION_MAJOR=7 \
39-
VERSION_MINOR=3 \
46+
ENV VERSION=8.0.0 \
47+
VERSION_MAJOR=8 \
48+
VERSION_MINOR=0 \
4049
VERSION_MICRO=0
4150

42-
FROM production AS test
51+
# Install the AWSCLI for moving match targets in the QC workflow.
52+
# See https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html#cliv2-linux-install
53+
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
54+
unzip awscliv2.zip && \
55+
./aws/install && \
56+
rm -rf aws awscliv2.zip
57+
58+
# This build target is for testing in Circle CI.
59+
FROM --platform=$PLATFORM production AS test
4360
COPY .circleci/test_image.py .
4461
COPY CHANGELOG.md .
4562

46-
# Defaults to production as the final stage
63+
# This build target is for updating dependencies.
64+
# See generate-requirements.full.sh.
65+
FROM --platform=$PLATFORM $BASE_IMAGE AS pip-tools
66+
RUN pip install -U --no-cache-dir pip pip-tools --progress-bar off
67+
CMD ["/bin/bash"]
68+
69+
# Default to the production build target.
4770
FROM production

buildspec/merge_master.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ phases:
33
pre_build:
44
commands:
55
- echo Logging in to Amazon ECR...
6-
- aws ecr get-login-password --region ${AWS_DEFAULT_REGION} | docker login --username AWS --password-stdin ${REPOSITORY_URI}
6+
- aws ecr get-login-password --region ${AWS_DEFAULT_REGION} | docker login --username AWS --password-stdin ${FIPS_REPOSITORY_URI}
77
build:
88
commands:
99
- echo Building the Docker image...
10-
- docker build -t ${REPOSITORY_URI}:latest .
11-
- docker image push --all-tags ${REPOSITORY_URI}
10+
- docker build -t ${FIPS_REPOSITORY_URI}:latest .
11+
- docker image push --all-tags ${FIPS_REPOSITORY_URI}
1212
post_build:
1313
commands:
1414
- echo Build completed!

buildspec/push.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: 0.2
2+
phases:
3+
build:
4+
commands:
5+
- echo Logging in to Amazon ECR...
6+
- aws ecr get-login-password --region ${AWS_DEFAULT_REGION} | docker login --username AWS --password-stdin ${FIPS_REPOSITORY_URI}
7+
- export COMMIT_HASH_SHORT="$(echo $COMMIT_HASH | cut -c 1-7)"
8+
- echo Building the Docker image...
9+
- echo $FIPS_REPOSITORY_URI
10+
- echo $COMMIT_HASH_SHORT
11+
- echo $BRANCH_NAME
12+
- docker build --tag ${FIPS_REPOSITORY_URI}:${COMMIT_HASH_SHORT} --tag ${FIPS_REPOSITORY_URI}:${BRANCH_NAME} .
13+
# This config tests the codebuild login and the build but does not push dev images.
14+
# The following lines can be temporarily uncommented to test a dev image.
15+
# - docker image push --all-tags ${FIPS_REPOSITORY_URI}
16+
post_build:
17+
commands:
18+
- echo Build completed!
19+
- printf '{"tag":"%s"}' $COMMIT_HASH_SHORT > build.json

buildspec/release.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ phases:
44
build:
55
commands:
66
- echo Logging in to Amazon ECR...
7-
- aws ecr get-login-password --region ${AWS_DEFAULT_REGION} | docker login --username AWS --password-stdin ${REPOSITORY_URI}
7+
- aws ecr get-login-password --region ${AWS_DEFAULT_REGION} | docker login --username AWS --password-stdin ${FIPS_REPOSITORY_URI}
88
- echo Building the Docker image...
99
- PATCH_TAG=${TAG_NAME#"v"} # major.minor.patch
1010
- MINOR_TAG=${PATCH_TAG%.*} # major.minor
1111
- MAJOR_TAG=${MINOR_TAG%.*} # major
12-
- docker build -t ${REPOSITORY_URI}:${PATCH_TAG} -t ${REPOSITORY_URI}:${MINOR_TAG} -t ${REPOSITORY_URI}:${MAJOR_TAG} .
13-
- docker image push --all-tags ${REPOSITORY_URI}
12+
- docker build -t ${FIPS_REPOSITORY_URI}:${PATCH_TAG} -t ${FIPS_REPOSITORY_URI}:${MINOR_TAG} -t ${FIPS_REPOSITORY_URI}:${MAJOR_TAG} .
13+
- docker image push --all-tags ${FIPS_REPOSITORY_URI}
1414
post_build:
1515
commands:
1616
- echo Build completed!

docker-compose.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
services:
2+
pip-tools:
3+
build:
4+
context: .
5+
dockerfile: ./Dockerfile
6+
target: pip-tools
7+
volumes:
8+
- .:/app
9+
stdin_open: true
10+
tty: true
11+
working_dir: /app

generate-requirements-full.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2-
python --version
3-
pip install --upgrade pip-tools
4-
pip-compile --output-file=requirements-full.txt --pip-args='--prefer-binary' --strip-extras --upgrade requirements-core.txt
2+
# Run this script to update requirements-core.txt.
3+
# It uses Docker to ensure that the environment matches what will be used in the production image.
4+
set -e
5+
docker compose run --rm pip-tools /bin/sh -c "pip install --upgrade pip-tools && pip-compile --output-file=requirements-full.txt --pip-args='--prefer-binary' --strip-extras --upgrade requirements-core.txt"

requirements-core.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
awscli==1.33.9
21
boto3==1.34.127
32
civis==2.3.0
43
numpy==2.0.0

requirements-full.txt

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,17 @@
44
#
55
# pip-compile --output-file=requirements-full.txt --pip-args='--prefer-binary' --strip-extras requirements-core.txt
66
#
7-
attrs==23.2.0
7+
attrs==24.2.0
88
# via
99
# jsonschema
1010
# referencing
11-
awscli==1.33.9
12-
# via -r requirements-core.txt
1311
boto3==1.34.127
1412
# via -r requirements-core.txt
15-
botocore==1.34.127
13+
botocore==1.34.162
1614
# via
17-
# awscli
1815
# boto3
1916
# s3transfer
20-
certifi==2024.6.2
17+
certifi==2024.7.4
2118
# via requests
2219
charset-normalizer==3.3.2
2320
# via requests
@@ -27,11 +24,7 @@ click==8.1.7
2724
# via civis
2825
cloudpickle==3.0.0
2926
# via civis
30-
colorama==0.4.6
31-
# via awscli
32-
docutils==0.16
33-
# via awscli
34-
idna==3.7
27+
idna==3.8
3528
# via requests
3629
jmespath==1.0.1
3730
# via
@@ -43,7 +36,7 @@ joblib==1.4.2
4336
# scikit-learn
4437
jsonref==1.1.0
4538
# via civis
46-
jsonschema==4.22.0
39+
jsonschema==4.23.0
4740
# via civis
4841
jsonschema-specifications==2023.12.1
4942
# via jsonschema
@@ -55,18 +48,14 @@ numpy==2.0.0
5548
# scipy
5649
pandas==2.2.2
5750
# via -r requirements-core.txt
58-
pyasn1==0.6.0
59-
# via rsa
6051
python-dateutil==2.9.0.post0
6152
# via
6253
# botocore
6354
# pandas
6455
pytz==2024.1
6556
# via pandas
66-
pyyaml==6.0.1
67-
# via
68-
# awscli
69-
# civis
57+
pyyaml==6.0.2
58+
# via civis
7059
referencing==0.35.1
7160
# via
7261
# jsonschema
@@ -75,16 +64,12 @@ requests==2.32.3
7564
# via
7665
# -r requirements-core.txt
7766
# civis
78-
rpds-py==0.18.1
67+
rpds-py==0.20.0
7968
# via
8069
# jsonschema
8170
# referencing
82-
rsa==4.7.2
83-
# via awscli
84-
s3transfer==0.10.1
85-
# via
86-
# awscli
87-
# boto3
71+
s3transfer==0.10.2
72+
# via boto3
8873
scikit-learn==1.5.0
8974
# via -r requirements-core.txt
9075
scipy==1.13.1
@@ -93,7 +78,7 @@ scipy==1.13.1
9378
# scikit-learn
9479
six==1.16.0
9580
# via python-dateutil
96-
tenacity==8.4.1
81+
tenacity==9.0.0
9782
# via civis
9883
threadpoolctl==3.5.0
9984
# via scikit-learn

0 commit comments

Comments
 (0)