Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CodeArtifact for AWS CodeBuild CI jobs #1455

Merged
merged 8 commits into from
Jan 13, 2021

Conversation

bryceitoc9
Copy link
Contributor

@bryceitoc9 bryceitoc9 commented Jan 6, 2021

  • Doing some additional testing, want to ensure that the buildscripts don't attempt to use CodeArtifact if env vars aren't present (I have confirmed that a CodePipeline tracking the child branch does use CodeArtifact correctly). Confirmed
    • Our main CI and Github Actions/Travis accounts are currently not wired up for CodeArtifact and should skip the CodeArtifact pre-build step. Tests run against this PR should confirm this. Confirmed
  • We may need to roll back Windows CodeArtifact usage. This is because we can't update our Windows builds to the newer CodeBuild image (required by CodeBuild): Extension tests are not running in a windows docker container microsoft/vscode#77499 Rolled back

Description

This change implements CodeArtifact as a cache for NPM for CI jobs run by AWS CodeBuild. This gives us insurance that we can build and deploy VS Code even if NPM goes down.

Additionally, moved to npm ci for install to ensure only the packages in the package-lock are built.

Motivation and Context

We don't want to be in a place where we need a fix that we can't deploy due to issues with CI.

Testing

Tested against a private AWS account. Deploying these changes to a CodePipeline tracking the child branch resulted in a CodeArtifact repo being populated with the appropriate packages.

Screenshots (if appropriate)

Checklist

  • I have read the README document
  • I have read the CONTRIBUTING document
  • My code follows the code style of this project
  • I have added tests to cover my changes
  • All new and existing tests passed
  • A short description of the change has been added to the changelog using the script npm run newChange

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@bryceitoc9
Copy link
Contributor Author

/runintegrationtests

@bryceitoc9
Copy link
Contributor Author

bryceitoc9 commented Jan 6, 2021

Looks like it worked! Executions from my CI look like:
Linux:

[Container] 2021/01/06 19:22:22 Entering phase PRE_BUILD
[Container] 2021/01/06 19:22:22 Running command if [ $CODEARTIFACT_DOMAIN ] && [ $CODEARTIFACT_REPO ] && [ $ACCOUNT_ID ]; then
  aws codeartifact login --tool npm --domain "$CODEARTIFACT_DOMAIN" --domain-owner "$ACCOUNT_ID" --repository "$CODEARTIFACT_REPO"
fi

Successfully configured npm to use AWS CodeArtifact repository <URL>
Login expires in 12 hours at 2021-01-07 07:22:27+00:00

[Container] 2021/01/06 19:22:28 Running command npm ci --unsafe-perm

Windows:

[Container] 2021/01/06 19:24:21 Entering phase PRE_BUILD
[Container] 2021/01/06 19:24:21 Running command if ($Env:CODEARTIFACT_DOMAIN -and $Env:CODEARTIFACT_REPO -and $Env:ACCOUNT_ID) {
  aws codeartifact login --tool npm --domain "$CODEARTIFACT_DOMAIN" --domain-owner "$ACCOUNT_ID" --repository "$CODEARTIFACT_REPO"
}

Successfully configured npm to use AWS CodeArtifact repository <URL>

Login expires in 12 hours at 2021-01-07 07:24:27+00:00

[Container] 2021/01/06 19:24:39 Running command npm ci

Logs from executions tied to this PR skip the success confirmations.

@bryceitoc9
Copy link
Contributor Author

bryceitoc9 commented Jan 8, 2021

New command correctly hides CodeArtifact URL:

2021-01-07T03:56:11.308-08:00	[Container] 2021/01/07 23:56:07 Entering phase PRE_BUILD
2021-01-07T03:56:11.308-08:00	[Container] 2021/01/07 23:56:07 Running command if [ $CODEARTIFACT_DOMAIN ] && [ $CODEARTIFACT_REPO ] && [ $ACCOUNT_ID ]; then
2021-01-07T03:56:11.308-08:00	  aws codeartifact login --tool npm --domain "$CODEARTIFACT_DOMAIN" --domain-owner "$ACCOUNT_ID" --repository "$CODEARTIFACT_REPO" > /dev/null 2>&1
2021-01-07T03:56:11.308-08:00	  if [ $? -eq 0 ]; then
2021-01-07T03:56:11.308-08:00	    echo "Connected to CodeArtifact"
2021-01-07T03:56:11.308-08:00	  else
2021-01-07T03:56:11.308-08:00	    echo "CodeArtifact connection failed. Falling back to npm"
2021-01-07T03:56:11.308-08:00	  fi
2021-01-07T03:56:11.308-08:00	fi
2021-01-07T03:56:11.308-08:00	
2021-01-07T03:56:15.376-08:00	Connected to CodeArtifact
2021-01-07T03:56:15.376-08:00	
2021-01-07T03:56:15.376-08:00	[Container] 2021/01/07 23:56:14 Running command npm ci --unsafe-perm

Windows does not run CodeArtifact (commented out for now).

@bryceitoc9 bryceitoc9 marked this pull request as ready for review January 8, 2021 00:06
@bryceitoc9 bryceitoc9 requested a review from a team as a code owner January 8, 2021 00:06
@bryceitoc9
Copy link
Contributor Author

bryceitoc9 commented Jan 8, 2021

/runintegrationtests

else
echo "CodeArtifact connection failed. Falling back to npm"
fi
fi
Copy link
Contributor

@justinmk3 justinmk3 Jan 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run this block through https://www.shellcheck.net/ . It has several issues. E.g. missing quotes around env vars.

shellcheck's SC2181 is suggesting this change:

                  if aws codeartifact login --tool npm --domain "$TOOLKITS_CODEARTIFACT_DOMAIN" --domain-owner "$ACCOUNT_ID" --repository "$TOOLKITS_CODEARTIFACT_REPO" > /dev/null 2>&1 ; then
                    echo "Connected to CodeArtifact"
                  else
                    echo "CodeArtifact connection failed. Falling back to npm"
                  fi

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got a Powershell equivalent? 😛

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:) Not sure, but powershell has many fewer gotchas.

@bryceitoc9
Copy link
Contributor Author

/retryBuilds

@bryceitoc9 bryceitoc9 merged commit a8fc238 into master Jan 13, 2021
@bryceitoc9 bryceitoc9 deleted the bryceito/use-codeartifact branch January 13, 2021 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants