Skip to content

Commit

Permalink
[ci] Upload built Docker images to ECR
Browse files Browse the repository at this point in the history
  • Loading branch information
driazati committed Mar 22, 2022
1 parent cf831ac commit a9d5de8
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 28 deletions.
46 changes: 42 additions & 4 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,57 @@ def build_image(image_name) {
def full_name = "${image_name}:${env.BRANCH_NAME}-${hash}"
sh(
script: "${docker_build} ${image_name} --spec ${full_name}",
label: 'Building docker image'
label: 'Build docker image'
)
aws_account_id = sh(
returnStdout: true,
script: 'aws sts get-caller-identity | grep Account | cut -f4 -d\\"',
label: 'Get AWS ID'
).trim()

try {
// Use a credential so Jenkins knows to scrub the AWS account ID which is nice
// (but so we don't have to rely it being hardcoded in Jenkins)
withCredentials([string(
credentialsId: 'aws-account-id',
variable: '_ACCOUNT_ID_DO_NOT_USE',
)]) {
withEnv([
"AWS_ACCOUNT_ID=${aws_account_id}",
'AWS_DEFAULT_REGION=us-west-2']) {
sh(
script: '''
set -x
aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
''',
label: 'Log in to ECR'
)
sh(
script: """
set -x
docker tag ${full_name} \$AWS_ACCOUNT_ID.dkr.ecr.\$AWS_DEFAULT_REGION.amazonaws.com/${full_name}
docker push \$AWS_ACCOUNT_ID.dkr.ecr.\$AWS_DEFAULT_REGION.amazonaws.com/${full_name}
""",
label: 'Upload image to ECR'
)
}
}
} finally {
sh(
script: 'rm -f ~/.docker/config.json',
label: 'Clean up login credentials'
)
}
sh(
script: "docker rmi ${full_name}",
label: 'Removing docker image'
label: 'Remove docker image'
)
sh "echo NYI: Uploading docker image to registry..."
}

if (rebuild_docker_images) {
stage('Docker Image Build') {
// TODO in a follow up PR: Upload to ECR, find tag and use in
// subsequent builds
// TODO in a follow up PR: Find ecr tag and use in subsequent builds
parallel 'ci-lint': {
node('CPU') {
timeout(time: max_time, unit: 'MINUTES') {
Expand Down
48 changes: 24 additions & 24 deletions docker/Dockerfile.ci_lint
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,36 @@ RUN apt-get update --fix-missing

RUN apt-get update && apt-get install -y wget git sudo make

COPY install/ubuntu1804_install_python.sh /install/ubuntu1804_install_python.sh
RUN bash /install/ubuntu1804_install_python.sh
# COPY install/ubuntu1804_install_python.sh /install/ubuntu1804_install_python.sh
# RUN bash /install/ubuntu1804_install_python.sh

# Globally disable pip cache
RUN pip config set global.no-cache-dir false
# # Globally disable pip cache
# RUN pip config set global.no-cache-dir false

RUN apt-get update && apt-get install -y doxygen graphviz curl shellcheck
# RUN apt-get update && apt-get install -y doxygen graphviz curl shellcheck

RUN pip3 install cpplint pylint==2.4.4 mypy==0.902 black==20.8b1 flake8==3.9.2
# RUN pip3 install cpplint pylint==2.4.4 mypy==0.902 black==20.8b1 flake8==3.9.2

# Rust env (build early; takes a while)
COPY install/ubuntu_install_rust.sh /install/ubuntu_install_rust.sh
RUN bash /install/ubuntu_install_rust.sh
ENV RUSTUP_HOME /opt/rust
ENV CARGO_HOME /opt/rust
ENV PATH $PATH:$CARGO_HOME/bin
# # Rust env (build early; takes a while)
# COPY install/ubuntu_install_rust.sh /install/ubuntu_install_rust.sh
# RUN bash /install/ubuntu_install_rust.sh
# ENV RUSTUP_HOME /opt/rust
# ENV CARGO_HOME /opt/rust
# ENV PATH $PATH:$CARGO_HOME/bin

# java deps for rat
COPY install/ubuntu_install_java.sh /install/ubuntu_install_java.sh
RUN bash /install/ubuntu_install_java.sh
# # java deps for rat
# COPY install/ubuntu_install_java.sh /install/ubuntu_install_java.sh
# RUN bash /install/ubuntu_install_java.sh

COPY install/ubuntu_install_rat.sh /install/ubuntu_install_rat.sh
RUN bash /install/ubuntu_install_rat.sh
# COPY install/ubuntu_install_rat.sh /install/ubuntu_install_rat.sh
# RUN bash /install/ubuntu_install_rat.sh

COPY install/ubuntu1804_install_clang_format.sh /install/ubuntu1804_install_clang_format.sh
RUN bash /install/ubuntu1804_install_clang_format.sh
# COPY install/ubuntu1804_install_clang_format.sh /install/ubuntu1804_install_clang_format.sh
# RUN bash /install/ubuntu1804_install_clang_format.sh

COPY install/ubuntu_install_nodejs.sh /install/ubuntu_install_nodejs.sh
RUN bash /install/ubuntu_install_nodejs.sh
# COPY install/ubuntu_install_nodejs.sh /install/ubuntu_install_nodejs.sh
# RUN bash /install/ubuntu_install_nodejs.sh

# To prevent `black` command line errors caused by ASCII encoding
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
# # To prevent `black` command line errors caused by ASCII encoding
# ENV LC_ALL=C.UTF-8
# ENV LANG=C.UTF-8

0 comments on commit a9d5de8

Please sign in to comment.