Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save lotharschulz/291a46c4e573d99fb3d9ffd710a38ac4 to your computer and use it in GitHub Desktop.

Select an option

Save lotharschulz/291a46c4e573d99fb3d9ffd710a38ac4 to your computer and use it in GitHub Desktop.

Revisions

  1. lotharschulz revised this gist Aug 20, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion PublishingArtifactsWithAWSCodeartifactAndGitHubPackages.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Publishing artifacts with [AWS Codeartifact](https://aws.amazon.com/codeartifact/) and [GitHub Packages](https://github.com/features/packages)

    - Blog Post: [Publishing artifacts with AWS Codeartifact and GitHub Packages](medium.....)
    - Blog Post: [Publishing artifacts with AWS Codeartifact and GitHub Packages](https://medium.com/reachnow-tech/publishing-artifacts-with-aws-codeartifact-and-github-packages-ca6102e87a47)
    - GitHub repository with full code details: [reach-now/codeartifact-packages-publishing](https://github.com/reach-now/codeartifact-packages-publishing)

    ## AWS Codeartifact
  2. lotharschulz revised this gist Aug 16, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions PublishingArtifactsWithAWSCodeartifactAndGitHubPackages.md
    Original file line number Diff line number Diff line change
    @@ -182,6 +182,7 @@ mavenPassword=[GitHub Personal Access Token]

    terminal
    ```
    ./gradlew install
    ./gradlew run
    ```

    @@ -190,6 +191,7 @@ in another terminal
    curl http://0.0.0.0:8080/lib
    Kotlin
    ```

    ### NPM

    #### publish artifact
  3. lotharschulz created this gist Aug 16, 2020.
    227 changes: 227 additions & 0 deletions PublishingArtifactsWithAWSCodeartifactAndGitHubPackages.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,227 @@
    # Publishing artifacts with [AWS Codeartifact](https://aws.amazon.com/codeartifact/) and [GitHub Packages](https://github.com/features/packages)

    - Blog Post: [Publishing artifacts with AWS Codeartifact and GitHub Packages](medium.....)
    - GitHub repository with full code details: [reach-now/codeartifact-packages-publishing](https://github.com/reach-now/codeartifact-packages-publishing)

    ## AWS Codeartifact

    #### Repository Setup

    aws cli
    ```sh
    # create domain
    aws codeartifact create-domain --domain some-domain

    # create repo
    aws codeartifact create-repository \
    --domain some-domain \
    --repository some-repository
    ```

    #### Access Tokens

    aws cli
    ```sh
    export CODEARTIFACT_AUTH_TOKEN=$(aws codeartifact get-authorization-token \
    --domain some-domain \
    --domain some-repository \
    --query authorizationToken \
    --output text)
    ```

    ### NPM

    #### publish artifact

    terminal
    ```sh
    cd npm/some-library
    export REPOSITORY_ENDPOINT=$(aws codeartifact get-repository-endpoint \
    --domain some-domain \
    --repository some-repository \
    --format npm \
    --query repositoryEndpoint \
    --output text)
    cat << EOF > .npmrc
    @reach-now:registry=$REPOSITORY_ENDPOINT
    ${REPOSITORY_ENDPOINT#https:}:always-auth=true
    ${REPOSITORY_ENDPOINT#https:}:_authToken=\${CODEARTIFACT_AUTH_TOKEN}
    EOF
    ```

    ```sh
    npm install
    npm publish
    ```

    #### retrieve artifact

    terminal
    ```sh
    cd npm/some-app
    cp ../some-library/.npmrc .
    grep some-library < package.json
    "@reach-now/some-library": "^1.0.0"
    npm install
    node index.js
    ohai: πŸ”” πŸ”” πŸ””
    ```

    ### Gradle

    #### publish artifact

    terminal
    ```sh
    export REPOSITORY_ENDPOINT=$(aws codeartifact get-repository-endpoint \
    --domain some-domain \
    --repository some-repositiory \
    --format maven \
    --query repositoryEndpoint \
    --output text)
    echo "reachnowRepoUrl=$REPOSITORY_ENDPOINT" > gradle.properties
    ```

    Gradle Kotlin DSL
    ```kts
    publishing {
    ...
    repositories {
    maven {
    val reachnowRepoUrl: String by project
    url = uri(reachnowRepoUrl)
    credentials {
    username = "aws"
    password = System.getenv("CODEARTIFACT_AUTH_TOKEN")
    }
    }
    }
    }
    ```

    terminal
    ```sh
    gradle clean build publish
    ```
    #### retrieve artifact

    Gradle Groovy DSL
    ```groovy
    repositories {
    mavenCentral()
    maven { url "https://jcenter.bintray.com" }
    maven {
    url reachnowRepoUrl
    credentials {
    username "aws"
    password System.env.CODEARTIFACT_AUTH_TOKEN
    }
    }
    }
    ...
    dependencies {
    ...
    implementation "com.reachnow:some-library:0.0.1"
    }
    ```

    terminal
    ```sh
    gradle clean build jar
    java -jar build/libs/some-app-0.1-all.jar

    curl localhost:8080/hello
    Bus
    ```

    ## GitHub Packages

    ### Gradle

    #### publish artifact

    Gradle Kotlin DSL
    ```kts
    publishing {
    repositories {
    maven {
    name = "GitHubPackages"
    url = uri("https://maven.pkg.github.com/reach-now/codeartifact-packages-publishing/")
    credentials {
    username = project.findProperty("gpr.user") as String?
    password = project.findProperty("gpr.key") as String?
    }
    }
    }
    publications {
    create<MavenPublication>("gpr") {
    from(components["java"])
    groupId = groupId
    version = version

    }
    }
    ```

    GitHub workflow file
    ```yaml

    - run: ./gradlew \
    -Pgpr.user=[username] \
    -Pgpr.key=${{ secrets.[GitHub-secret-id] }} publish

    ```

    #### retrieve artifact

    gradle properties file
    ```
    mavenUser=[Your Github Username]
    mavenPassword=[GitHub Personal Access Token]
    ```

    terminal
    ```
    ./gradlew run
    ```

    in another terminal
    ```
    curl http://0.0.0.0:8080/lib
    Kotlin
    ```
    ### NPM

    #### publish artifact

    package.json
    ```json
    "repository": {
    "type": "git",
    "url": "ssh://[email protected]/reach-now/codeartifact-packages-publishing.git",
    "directory": "packages/name"
    }
    ```

    GitHub workflow file
    ```yaml
    - run: npm publish
    env:
    NODE_AUTH_TOKEN: ${{ secrets.[GitHub-secret-id] }}
    ```

    #### retrieve artifact

    terminal
    ```sh
    $ npm login --registry=https://npm.pkg.github.com
    > Username: USERNAME
    > Password: GITHUB_PERSONAL_ACCESS_TOKEN_VALUE
    > Email: PUBLIC-EMAIL-ADDRESS
    ```

    ```sh
    $ npm i
    $ node index.js
    ohai: πŸ”” πŸ”” πŸ””
    ```