AWS SAM Unable to access Maven package published on Github Package - java

I have successfully published a Maven Package to Github Packages.
Looks like this on the Github packages page:
<dependency>
<groupId>com.conectar.meetings</groupId>
<artifactId>github-meetings-serverless-lib</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
But when I try to use this package in my AWS SAM application, I get an error trying to install it.
It fails on the build step of my SAM app even though I supply the GITHUB_TOKEN as an env var:
- name: SAM Build for Prod Environment
run: |
cd $GITHUB_WORKSPACE
sam build --parameter-overrides EnvStage=prod TableName=${{ secrets.PROD_DB_TABLENAME }} && sam package --s3-bucket ${{ secrets.PROD_AWS_DEPLOY_BUCKET }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_REGION }}
Here's the build error:
Downloaded from central: https://repo.maven.apache.org/maven2/software/amazon/ion/ion-java/1.0.2/ion-java-1.0.2.jar (565 kB at 333 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/httpcomponents/httpclient/4.5.12/httpclient-4.5.12.jar (778 kB at 458 kB/s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.056 s
[INFO] Finished at: 2021-03-12T12:55:57Z
[INFO] ------------------------------------------------------------------------
Error: Failed to execute goal on project CreateMeeting: Could not resolve dependencies for project CreateMeeting:CreateMeeting:jar:1.0: Could not find artifact com.conectar.meetings:github-meetings-serverless-lib:jar:0.0.1-SNAPSHOT -> [Help 1]
Error:
Error: To see the full stack trace of the errors, re-run Maven with the -e switch.
Error: Re-run Maven using the -X switch to enable full debug logging.
Error:
Error: For more information about the errors and possible solutions, please read the following articles:
Error: [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
Error: Process completed with exit code 1.
Why can't it find the artifact?
I expect it to use the GITHUB_TOKEN to authenticate the build, but it seems to not be using that.
The package is published in the same repo where Github action is also running.
How do I make AWS SAM know about this Github Package?

Related

GitHub Actions: Error 401 Unauthorized in JIB maven plugin

Introduction
I am currently to create a composite GitHub Actions that build a container from Java project with JIB and publish it automatically to a GitHub Packages and Maven Central.
Problematic
But I got this error when I try to run it:
[INFO]
[INFO] Containerizing application to gcr.io/mathieusoysal/codingame-puzzles-stats-saver:v1.0.2.5...
Warning: Base image 'eclipse-temurin:17-jre' does not use a specific image digest - build may not be reproducible
[INFO] Using credentials from <to><auth> for gcr.io/mathieusoysal/codingame-puzzles-stats-saver:v1.0.2.5
[INFO] Getting manifest for base image eclipse-temurin:17-jre...
[INFO] Building dependencies layer...
[INFO] Building resources layer...
[INFO] Building classes layer...
[INFO] Building jvm arg files layer...
[INFO] The base image requires auth. Trying again for eclipse-temurin:17-jre...
[INFO] Using credentials from Docker config (/home/runner/.docker/config.json) for eclipse-temurin:17-jre
[INFO] Using base image with digest: sha256:e7a4a45b88525250e668cc6149b95b3952a8e9cba8c341b70c4d34c4e4d5eed5
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.272 s
[INFO] Finished at: 2022-02-09T00:37:22Z
[INFO] ------------------------------------------------------------------------
Error: Failed to execute goal com.google.cloud.tools:jib-maven-plugin:3.2.0:build (default-cli) on project codingame-puzzles-stats-saver: Build image failed, perhaps you should make sure your credentials for 'gcr.io/mathieusoysal/codingame-puzzles-stats-saver' are set up correctly. See https://github.com/GoogleContainerTools/jib/blob/master/docs/faq.md#what-should-i-do-when-the-registry-responds-with-unauthorized for help: Unauthorized for gcr.io/mathieusoysal/codingame-puzzles-stats-saver: 401 Unauthorized
Error: {"errors":[{"code":"UNAUTHORIZED","message":"Not Authorized."}]}
Error: -> [Help 1]
Error:
Error: To see the full stack trace of the errors, re-run Maven with the -e switch.
Error: Re-run Maven using the -X switch to enable full debug logging.
Error:
Error: For more information about the errors and possible solutions, please read the following articles:
Error: [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Error: Process completed with exit code 1.
Affected code:
name: JIB container publish
description: "Build automatically container with JIB and publish it to GitHub Packages."
branding:
icon: "package"
color: "gray-dark"
inputs:
# Use docker.io for Docker Hub if empty
REGISTRY:
description: "Registry of the image to publish"
required: true
default: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME:
description: "Name of the image to publish"
required: true
default: ${{ github.repository }}
# Username to login to registry
USERNAME:
description: "Username to login to registry"
required: true
default: ${{ github.actor }}
# Password to login to registry
PASSWORD:
description: "Password to login to registry"
required: true
# Name of the tag to publish
tag-name:
description: "Tag name of the image to publish"
required: true
default: "latest"
# Java version to use
java-version:
description: "Java version to use"
required: true
default: "17"
runs:
using: "composite"
steps:
- id: downcase
uses: ASzc/change-string-case-action#v2
with:
string: ${{ inputs.IMAGE_NAME }}
- uses: actions/checkout#v2
- name: Set up JDK 17
uses: actions/setup-java#v2
with:
distribution: "adopt"
java-version: ${{ inputs.java-version }}
- name: Buil JIB container and publish to GitHub Packages
run: |
mvn compile com.google.cloud.tools:jib-maven-plugin:3.2.0:build \
-Djib.to.image=${{ inputs.REGISTRY }}/${{ steps.downcase.outputs.lowercase }}:${{ inputs.tag-name }} \
-Djib.to.auth.username=${{ inputs.USERNAME }} \
-Djib.to.auth.password=${{ inputs.PASSWORD }}
shell: bash
Code that execute the GitHub Actions in question:
name: Deploy Javadoc
on:
name: JIB container publish
on:
release:
types: [created]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: JIB container build and publish
uses: MathieuSoysal/jib-container-publish.yml#v2.0.7
with:
# Use docker.io for Docker Hub if empty
REGISTRY: gcr.io
# github.repository as <your-account>/<your-repo>
IMAGE_NAME: ${{ github.repository }}
# Tag name of the image to publish
tag-name: ${{ github.event.release.tag_name }}
# Username to login to registry
USERNAME: ${{ github.actor }}
# Password to login to registry
PASSWORD: ${{ secrets.GITHUB_TOKEN }}
java-version: 17
Question
Anyone have an idea to solve this problem?
Link of the repo: https://github.com/MathieuSoysal/jib-container-publish.yml
Everything looks good. Jib retrieved credentials from -Dto.auth.{username|password}.
Using credentials from <to><auth> for gcr.io/mathieusoysal/codingame-puzzles-stats-saver:v1.0.2.5
I suspect that you are just not passing the right "username" and "password" for gcr.io (Google Container Registry, which is different from ghcr.io). From this doc,
Note: This method of authentication should be used only as a last resort, as it is insecure to make your password visible in plain text. Note that often cloud registries (for example, Google GCR, Amazon ECR, and Azure ACR) do not accept "user credentials" (such as Gmail account name and password) but require different forms of credentials. For example, you may use oauth2accesstoken or _json_key as the username for GCR, and AWS for ECR. For ACR, you may use a service principle.
AFAICT, for GCR, to.auth.username would be either oath2accesstoken or _json_key literally. It doesn't make sense that the username is ${{ github.actor }}.
Aside, you should make sure that the auth arguments you pass on the command-line is not logged or shown for security. Take a look at this Stack Overflow answer to understand general registry authentication.
Also, typically you'll want auth for both the "from" image and "to" image.

Getting started with AWS SDK for Java

I'm very new to the AWS SDK for Java. I'm trying to get started with the AWS SDK for Java 2.x following the documentation here (https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html#get-started-projectsetup)
But when I tried to create a project as mentioned here using the following command
mvn -B archetype:generate \-DarchetypeGroupId=org.apache.maven.archetypes \-DgroupId=com.example.myapp \-DartifactId=myapp
I'm getting an error:
PS C:\Users\robert\Desktop> mvn -B archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.example.myapp -DartifactId=myapp
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.100 s
[INFO] Finished at: 2021-08-09T12:26:24-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (C:\Users\robert\Desktop). Please verify you invoked Maven from
the correct directory. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MissingProjectExceptio
How to create a maven project and get started with aws sdk?
Do you have / chars in the command. If so, you need to use this command:
mvn -B archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.example.myapp -DartifactId=myapp
I'm using JDK 1.8 and this command is successful.
In Powershell you can't have the period (dot or full stop character) in your command line arguments. The instructions on that page lack this information and assume either a Unix-like environment or the cmd environment. You should run:
mvn -B archetype:generate "-DarchetypeGroupId=org.apache.maven.archetypes" "-DgroupId=com.example.myapp" -DartifactId=myapp

Maven Sonarqube plugin: Unable to execute SonarQube: Fail to get bootstrap index from server

I'm having an headache setting up the sonarqube maven plugin for a project.
So I have a sonarqube instance let's say on https://sonarqube.mycompany.software. I test many projects on this instance, it's working well since months.
I also have other projects that use the maven plugin (but use another docker image to run)
I start a new project, and of course I want to add to my automatic pipeline that checks the code with sonarqube.
Everything runs perfectly when I execute the maven plugin on my machine, with the OpenJdk-8:
$ mvn org.jacoco:jacoco-maven-plugin:0.8.5:prepare-agent clean test package
$ mvn sonar:sonar -Dsonar.projectKey=projectname -Dsonar.host.url=https://sonarqube.mycompany.software -Dsonar.login=youwishyouknew
[... Lots of output ...]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 16.891 s
[INFO] Finished at: 2020-05-07T18:03:00+02:00
[INFO] ------------------------------------------------------------------------
Then I try to execute the exact same command with docker on the server (where the pipeline will run), using the maven:3.6.3-jdk-8 image, I get this error:
$ docker run -v `pwd`/m2cache:/root/.m2 -v `pwd`/sonarcache:/root/.sonar/cache -v`pwd`:`pwd` -w`pwd` maven:3.6.3-jdk-8 mvn sonar:sonar -Dsonar.projectKey=projectname -Dsonar.host.url=https://sonarqube.mycompany.software -Dsonar.login=youwishyouknew
[INFO]
[INFO] ---------------------------< software.mycompany:projectname >----------------------------
[INFO] Building projectname 2.3.0
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- sonar-maven-plugin:3.7.0.1746:sonar (default-cli) # projectname ---
[INFO] User cache: /root/.sonar/cache
[ERROR] SonarQube server [https://sonarqube.mycompany.software] can not be reached
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.286 s
[INFO] Finished at: 2020-05-07T16:06:22Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project projectname: Unable to execute SonarQube: Fail to get bootstrap index from server: Broken pipe (Write failed) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
When I Execute this, absolutely nothing is happening in the Sonarqube logs (nothing moves at all in any log, while when I run it on my machine I find everything I expect to find.)
Furthermore, if I try to curl the sonarqube server from the docker image, it works! Tried with ping too.
$ docker run -v `pwd`/m2cache:/root/.m2 -v `pwd`/sonarcache:/root/.sonar/cache -v`pwd`:`pwd` -w`pwd` maven:3.6.3-jdk-8 curl https://sonarqube.mycompany.software
<!doctype html><html lang="en"><head><meta http-equiv="content-type" content="text/html; charset=UTF-8" charset="UTF-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge"><link rel="apple-touch-icon" href="/apple-touch-icon.png"><link rel="apple-touch-icon" sizes="57x57" href="/apple-touch-icon-57x57.png"><link rel="apple-touch-icon" sizes="60x60" href="/apple-touch-icon-60x60.png">
[... And a lot more output ... ]
It responds with the sonarqube index page as I expect.
As far as I can see, there is no proxy setting in the docker maven image.
This is quite frustrating.
Has anybody any clue on what is going on here and how to fix this?
[EDIT] So I've tried many things, and one worked: using another docker image. In particular, I've tried all the available maven jdk-8 images available here: https://hub.docker.com/_/maven, and one actually worked, while all other failed: maven:3.6.3-ibmjava-8.
It looks like a java-8 related problem, since all JDK 11 images instead do work as expected. Unfortunately the project is in Java 8 and everything breaks when upgrading the JVM :-)
I leave this here as a work-around, but still, I would like to know why it fails with other docker images and how to fix this in the future.
I had this issue too with maven and gradle sonarqube analysis, i have only this issue with jdk8-u252+.
Maven 3.6.3 official image have jdk8-u262.
For me, with maven 3.5.2 it's ok (jdk-u232).
For the root cause, it could be the javax.net.ssl new features shipped in u252 : https://www.oracle.com/java/technologies/javase/8u251-relnotes.html

Issue installing jhipster-registry

Excuse my lack of technicality concerning this matter, as i am a solely beginner.
so I'm trying to install a microservice application, so in order to do that , I need to install both gateway and microservice app and linked them through jhipster-registry(correct me if I'm wrong please).
now I've installed both of these apps succesfully. for the gateway I get this message message well presented through html "Your request cannot be processed" when i navigate to the localhost provided by the gateway console while getting this :
---------------------------------------------------------
Application 'gateway2' is running! Access URLs:
Local: http://localhost:8080/
External: http://192.168.56.1:8080/
Profile(s): [dev, swagger]
----------------------------------------------------------
2020-05-03 07:08:14.483 INFO 7600 --- [ restartedMain] com.mservice.app.Gateway2App :
----------------------------------------------------------
Config Server: Not found or not setup for this application
----------------------------------------------------------
same "Config Server" message I've gotten in the microservice app after the mvnw command
issue was when i run mvnw in this jhipster-registry folder I get this error in the end, now I've gone through some github issue and found contributors advising to run maven globaly sort of see if it's an environment issue, well nothing changed about the error.
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 54.986 s
[INFO] Finished at: 2020-05-03T07:00:00Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project jhipster-registry: Fatal error compiling: invalid flag: --release -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
maybe useful informations : I'm using JWT security, PosgreSQL database(and it's succesfully linked), havent implemented any entity in neither of the apps, I'm not using any docker
and if I'm understanding something worng, please point it out I would love for it to make sense.

CircleCI and Could not find goal 'go' in plugin org.apache.maven.plugins:maven-dependency-plugin:3.0.2

I try to run tests on multi modular spring project with leverage of CircleCI
I don't know why it's happen but when I try to run my spring boot project on CircleCI I get
[INFO] Reactor Summary for sfg-pet-clinic 0.0.5-SNAPSHOT:
[INFO]
[INFO] sfg-pet-clinic ..................................... SKIPPED
[INFO] pet-clinic-data .................................... SKIPPED
[INFO] pet-clinic-web ..................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.602 s
[INFO] Finished at: 2018-11-11T19:25:39Z
[INFO] ------------------------------------------------------------------------
[ERROR] Could not find goal 'go' in plugin org.apache.maven.plugins:maven-dependency-plugin:3.0.2 among available goals analyze, analyze-dep-mgt, analyze-duplicate, analyze-only, analyze-report, build-classpath, collect, copy, copy-dependencies, display-ancestors, get, go-offline, help, list, list-repositories, properties, purge-local-repository, resolve, resolve-plugins, sources, tree, unpack, unpack-dependencies -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoNotFoundException
Exited with code 1
but when I do tests manually, via Intellij everything is fine
this is my config.yml
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/openjdk:8-jdk
# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/postgres:9.4
working_directory: ~/repo
environment:
# Customize the JVM maximum heap limit
MAVEN_OPTS: -Xmx3200m
steps:
- checkout
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "pom.xml" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run: mvn dependency:go -DskipTests
- run: mvn dependency:go-offline
- save_cache:
paths:
- ~/.m2
key: v1-dependencies-{{ checksum "pom.xml" }}
# run tests!
- run: mvn integration-test
mvn dependency doesn't have a goal named 'go'. So the below line will fail.
run: mvn dependency:go -DskipTests
Please refer https://maven.apache.org/plugins/maven-dependency-plugin/

Categories

Resources