From b34299cdcadee1f03eed14dfb2a5c4059c61aea4 Mon Sep 17 00:00:00 2001 From: Calvin Rodo Date: Mon, 16 Aug 2021 16:43:54 -0400 Subject: [PATCH] feat: add aws cli to devcontainer (#76) fix: replace backslach in image names with dashes to deploy --- .devcontainer/Dockerfile | 12 ++++++++- .devcontainer/aws_cli.asc | 29 ++++++++++++++++++++++ .devcontainer/docker-compose.yml | 1 + .github/workflows/build_and_push.yml | 3 ++- .github/workflows/ci_build_continers.yml | 3 +-- .vscode/settings.json | 31 ++++++++++++++++++++++++ bin/test_dockerfilebuild.sh | 21 ++++++++++++++++ 7 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 .devcontainer/aws_cli.asc create mode 100644 .vscode/settings.json create mode 100755 bin/test_dockerfilebuild.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 27fe808b..178e3fa8 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -19,7 +19,7 @@ ARG TERRAGRUNT_CHECKSUM # Install packages RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ - && apt-get -y install --no-install-recommends awscli ca-certificates curl git gstreamer1.0-libav libnss3-tools libatk-bridge2.0-0 libcups2-dev libxkbcommon-x11-0 libxcomposite-dev libxrandr2 libgbm-dev libgtk-3-0 libxshmfence-dev gnupg2 jq make openssh-client python3-pip vim xz-utils zsh \ + && apt-get -y install --no-install-recommends ca-certificates curl git gstreamer1.0-libav libnss3-tools libatk-bridge2.0-0 libcups2-dev libxkbcommon-x11-0 libxcomposite-dev libxrandr2 libgbm-dev libgtk-3-0 libxshmfence-dev gnupg2 jq make openssh-client python3-pip vim xz-utils zsh \ && apt-get autoremove -y && apt-get clean -y # Install Terraform @@ -46,6 +46,16 @@ RUN curl -Lo shellcheck.tar.xz "https://github.com/koalaman/shellcheck/releases/ RUN pip3 install --upgrade requests setuptools \ && pip3 install --upgrade botocore checkov +# Install AWS CLI +ARG AWS_CLI_VERSION +COPY .devcontainer/aws_cli.asc ./ +RUN curl -Lo awscliv2.zip "https://awscli.amazonaws.com/awscli-exe-linux-x86_64-${AWS_CLI_VERSION}.zip" \ + && curl -Lo awscliv2.sig "https://awscli.amazonaws.com/awscli-exe-linux-x86_64-${AWS_CLI_VERSION}.zip.sig" \ + && gpg --import ./aws_cli.asc \ + && gpg --verify awscliv2.sig awscliv2.zip \ + && unzip awscliv2.zip \ + && ./aws/install -i /usr/local/aws-cli -b /usr/local/bin + # Setup aliases and autocomplete RUN echo "\n\ complete -C /usr/bin/aws_completer aws\n\ diff --git a/.devcontainer/aws_cli.asc b/.devcontainer/aws_cli.asc new file mode 100644 index 00000000..43990d9b --- /dev/null +++ b/.devcontainer/aws_cli.asc @@ -0,0 +1,29 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- + +mQINBF2Cr7UBEADJZHcgusOJl7ENSyumXh85z0TRV0xJorM2B/JL0kHOyigQluUG +ZMLhENaG0bYatdrKP+3H91lvK050pXwnO/R7fB/FSTouki4ciIx5OuLlnJZIxSzx +PqGl0mkxImLNbGWoi6Lto0LYxqHN2iQtzlwTVmq9733zd3XfcXrZ3+LblHAgEt5G +TfNxEKJ8soPLyWmwDH6HWCnjZ/aIQRBTIQ05uVeEoYxSh6wOai7ss/KveoSNBbYz +gbdzoqI2Y8cgH2nbfgp3DSasaLZEdCSsIsK1u05CinE7k2qZ7KgKAUIcT/cR/grk +C6VwsnDU0OUCideXcQ8WeHutqvgZH1JgKDbznoIzeQHJD238GEu+eKhRHcz8/jeG +94zkcgJOz3KbZGYMiTh277Fvj9zzvZsbMBCedV1BTg3TqgvdX4bdkhf5cH+7NtWO +lrFj6UwAsGukBTAOxC0l/dnSmZhJ7Z1KmEWilro/gOrjtOxqRQutlIqG22TaqoPG +fYVN+en3Zwbt97kcgZDwqbuykNt64oZWc4XKCa3mprEGC3IbJTBFqglXmZ7l9ywG +EEUJYOlb2XrSuPWml39beWdKM8kzr1OjnlOm6+lpTRCBfo0wa9F8YZRhHPAkwKkX +XDeOGpWRj4ohOx0d2GWkyV5xyN14p2tQOCdOODmz80yUTgRpPVQUtOEhXQARAQAB +tCFBV1MgQ0xJIFRlYW0gPGF3cy1jbGlAYW1hem9uLmNvbT6JAlQEEwEIAD4WIQT7 +Xbd/1cEYuAURraimMQrMRnJHXAUCXYKvtQIbAwUJB4TOAAULCQgHAgYVCgkICwIE +FgIDAQIeAQIXgAAKCRCmMQrMRnJHXJIXEAChLUIkg80uPUkGjE3jejvQSA1aWuAM +yzy6fdpdlRUz6M6nmsUhOExjVIvibEJpzK5mhuSZ4lb0vJ2ZUPgCv4zs2nBd7BGJ +MxKiWgBReGvTdqZ0SzyYH4PYCJSE732x/Fw9hfnh1dMTXNcrQXzwOmmFNNegG0Ox +au+VnpcR5Kz3smiTrIwZbRudo1ijhCYPQ7t5CMp9kjC6bObvy1hSIg2xNbMAN/Do +ikebAl36uA6Y/Uczjj3GxZW4ZWeFirMidKbtqvUz2y0UFszobjiBSqZZHCreC34B +hw9bFNpuWC/0SrXgohdsc6vK50pDGdV5kM2qo9tMQ/izsAwTh/d/GzZv8H4lV9eO +tEis+EpR497PaxKKh9tJf0N6Q1YLRHof5xePZtOIlS3gfvsH5hXA3HJ9yIxb8T0H +QYmVr3aIUes20i6meI3fuV36VFupwfrTKaL7VXnsrK2fq5cRvyJLNzXucg0WAjPF +RrAGLzY7nP1xeg1a0aeP+pdsqjqlPJom8OCWc1+6DWbg0jsC74WoesAqgBItODMB +rsal1y/q+bPzpsnWjzHV8+1/EtZmSc8ZUGSJOPkfC7hObnfkl18h+1QtKTjZme4d +H17gsBJr+opwJw/Zio2LMjQBOqlm3K1A4zFTh7wBC7He6KPQea1p2XAMgtvATtNe +YLZATHZKTJyiqA== +=vYOk +-----END PGP PUBLIC KEY BLOCK----- \ No newline at end of file diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index 53bdade8..20f4f806 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -19,6 +19,7 @@ services: TERRAFORM_CHECKSUM: "99c4866ffc4d3a749671b1f74d37f907eda1d67d7fc29ed5485aeff592980644" TERRAGRUNT_VERSION: "0.31.1" TERRAGRUNT_CHECKSUM: "76b253919ad688025a4a37338e5602543b0426cae1be1f863b4f3d60dd95ac28" + AWS_CLI_VERSION: "2.2.29" volumes: - ..:/workspace:cached command: sleep infinity diff --git a/.github/workflows/build_and_push.yml b/.github/workflows/build_and_push.yml index cfbf98bb..adab4067 100644 --- a/.github/workflows/build_and_push.yml +++ b/.github/workflows/build_and_push.yml @@ -69,8 +69,9 @@ jobs: - name: Deploy lambda run: | + FNAME = $(sed 's/\//-/g' <<< "${{ matrix.image }}") aws lambda update-function-code \ - --function-name ${{ matrix.image }} \ + --function-name "$FNAME" \ --image-uri $REGISTRY/${{ matrix.image }}:latest - name: Migrate Database diff --git a/.github/workflows/ci_build_continers.yml b/.github/workflows/ci_build_continers.yml index f7090b1a..eec0f394 100644 --- a/.github/workflows/ci_build_continers.yml +++ b/.github/workflows/ci_build_continers.yml @@ -25,7 +25,7 @@ jobs: scanners/axe-core: 'scanners/axe-core/**' scanners/owasp-zap: 'scanners/owasp-zap/**' - build-push-and-deploy: + build: if: ${{ needs.changes.outputs.images != '[]' }} runs-on: ubuntu-latest needs: changes @@ -43,5 +43,4 @@ jobs: run: | docker build \ --build-arg git_sha=$GITHUB_SHA \ - -t $REGISTRY/${{ matrix.image }}:$GITHUB_SHA \ -t $REGISTRY/${{ matrix.image }}:latest . diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..05abfcbf --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,31 @@ +{ + "yaml.customTags": [ + "!And", + "!And sequence", + "!If", + "!If sequence", + "!Not", + "!Not sequence", + "!Equals", + "!Equals sequence", + "!Or", + "!Or sequence", + "!FindInMap", + "!FindInMap sequence", + "!Base64", + "!Join", + "!Join sequence", + "!Cidr", + "!Ref", + "!Sub", + "!Sub sequence", + "!GetAtt", + "!GetAZs", + "!ImportValue", + "!ImportValue sequence", + "!Select", + "!Select sequence", + "!Split", + "!Split sequence" + ] +} \ No newline at end of file diff --git a/bin/test_dockerfilebuild.sh b/bin/test_dockerfilebuild.sh new file mode 100755 index 00000000..b2400796 --- /dev/null +++ b/bin/test_dockerfilebuild.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# Create a docker ignore to speed up context +cat << EOF > .dockerignore +* +!.devcontainer +EOF + +DOCKER_BUILDKIT=0 docker build . -f .devcontainer/Dockerfile \ + -t foo:bar \ + --build-arg VARIANT="3.9" \ + --build-arg INSTALL_NODE="true" \ + --build-arg NODE_VERSION="lts/*" \ + --build-arg SHELLCHECK_VERSION="0.7.2" \ + --build-arg SHELLCHECK_CHECKSUM="70423609f27b504d6c0c47e340f33652aea975e45f312324f2dbf91c95a3b188" \ + --build-arg TERRAFORM_VERSION="1.0.3" \ + --build-arg TERRAFORM_CHECKSUM="99c4866ffc4d3a749671b1f74d37f907eda1d67d7fc29ed5485aeff592980644" \ + --build-arg TERRAGRUNT_VERSION="0.31.1" \ + --build-arg TERRAGRUNT_CHECKSUM="76b253919ad688025a4a37338e5602543b0426cae1be1f863b4f3d60dd95ac28" \ + --build-arg AWS_CLI_VERSION="2.2.29" +rm .dockerignore \ No newline at end of file