Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to publish software artifacts with AWS Codeartifact and GitHub Packages

Publishing artifacts with AWS Codeartifact and GitHub Packages

AWS Codeartifact

Repository Setup

aws cli

# 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

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

NPM

publish artifact

terminal

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
npm install
npm publish

retrieve artifact

terminal

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

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

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

terminal

gradle clean build publish

retrieve artifact

Gradle Groovy DSL

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

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

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

    - 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 install
./gradlew run

in another terminal

curl http://0.0.0.0:8080/lib
Kotlin

NPM

publish artifact

package.json

  "repository": {
    "type": "git",
    "url": "ssh://git@github.com/reach-now/codeartifact-packages-publishing.git",
    "directory": "packages/name"
  }

GitHub workflow file

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

retrieve artifact

terminal

$ npm login --registry=https://npm.pkg.github.com
> Username: USERNAME
> Password: GITHUB_PERSONAL_ACCESS_TOKEN_VALUE
> Email: PUBLIC-EMAIL-ADDRESS
$ npm i
$ node index.js
ohai: 🔔 🔔 🔔
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.