Skip to content
This repository was archived by the owner on Nov 12, 2022. It is now read-only.

Commit a744aa0

Browse files
fix: Workflow updated and apk packages constraints adjusted (#13)
* Updated entrypoint and logic inside it to print non-json output as well (login and json params) * Anchor testing removed because creates too much false negative results * Functional test added
1 parent 9a8ab53 commit a744aa0

File tree

6 files changed

+93
-55
lines changed

6 files changed

+93
-55
lines changed

.github/workflows/CI.yaml

Lines changed: 53 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
name: Lint Code Base
1515
runs-on: ubuntu-latest
1616
steps:
17-
- name: Checkout Code
17+
- name: Checkout Code (Lint)
1818
uses: actions/checkout@v2
1919
- name: Lint Code Base
2020
uses: github/super-linter@v3
@@ -26,9 +26,26 @@ jobs:
2626
runs-on: ubuntu-latest
2727
outputs:
2828
tag: ${{ steps.info.outputs.tag }}
29+
repo: ${{ steps.info.outputs.repo }}
2930
steps:
30-
- name: Checkout Code
31+
# Preparation
32+
- name: Checkout Code (Testing)
3133
uses: actions/checkout@v2
34+
- name: Set up QEMU (Testing)
35+
uses: docker/setup-qemu-action@v1
36+
- name: Login to DockerHub (Testing)
37+
uses: docker/login-action@v1
38+
with:
39+
username: ${{ secrets.DOCKER_USERNAME }}
40+
password: ${{ secrets.DOCKER_PASSWORD }}
41+
# Test
42+
- name: Test help command
43+
uses: ./
44+
with:
45+
login: false
46+
json: false
47+
task: help
48+
# Info gathering
3249
- id: info
3350
run: |
3451
repo=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')
@@ -44,72 +61,61 @@ jobs:
4461
tag=$tag
4562
echo "::set-output name=repo::$repo"
4663
echo "::set-output name=tag::$tag"
47-
- name: Build and Push to GitHub registry Commit tag
48-
uses: elgohr/Publish-Docker-Github-Action@master
49-
with:
50-
name: docker.pkg.github.com/${{ github.repository }}/jelastic-cli
51-
username: ${{ github.repository_owner }}
52-
password: ${{ secrets.G_TOKEN }}
53-
registry: docker.pkg.github.com
54-
tags: "${{ steps.info.outputs.tag }}"
55-
- name: Login to GitHub Packages Docker Registry
56-
uses: docker/login-action@v1
64+
# Build
65+
- name: Build and Push image (Testing)
66+
uses: docker/build-push-action@v2
5767
with:
58-
registry: docker.pkg.github.com
59-
username: ${{ github.repository_owner }}
60-
password: ${{ secrets.G_TOKEN }}
61-
- name: Anchore scan
62-
uses: anchore/scan-action@v2
63-
with:
64-
image: "docker.pkg.github.com/${{ steps.info.outputs.repo }}/jelastic-cli:${{ steps.info.outputs.tag }}"
65-
fail-build: true
66-
acs-report-enable: true
67-
severity-cutoff: high
68-
- name: upload Anchore scan SARIF report
69-
uses: github/codeql-action/upload-sarif@v1
70-
with:
71-
sarif_file: results.sarif
68+
push: true
69+
tags: aliaksandrdounar/jelastic-cli:latest
7270

73-
docker:
71+
build:
7472
name: Build and Public Docker image
7573
runs-on: ubuntu-latest
7674
needs: [lint, test]
7775
steps:
78-
- name: Checkout Code
76+
# Prepare
77+
- name: Checkout Code (Build)
7978
uses: actions/checkout@v2
79+
- name: Set up QEMU (Build)
80+
uses: docker/setup-qemu-action@v1
81+
- name: Login to docker.pkg.github.com (Build)
82+
uses: docker/login-action@v1
83+
with:
84+
registry: docker.pkg.github.com
85+
username: ${{ github.repository_owner }}
86+
password: ${{ secrets.G_TOKEN }}
87+
- name: Login to DockerHub
88+
uses: docker/login-action@v1
89+
with:
90+
username: ${{ secrets.DOCKER_USERNAME }}
91+
password: ${{ secrets.DOCKER_PASSWORD }}
8092
- name: Dry-run tag generation
8193
id: create_tag_test
8294
uses: anothrNick/[email protected]
8395
env:
8496
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8597
WITH_V: true
8698
DRY_RUN: true
87-
- name: Build and Push to GitHub registry
88-
uses: elgohr/Publish-Docker-Github-Action@master
89-
with:
90-
name: docker.pkg.github.com/${{ github.repository }}/jelastic-cli
91-
username: ${{ github.repository_owner }}
92-
password: ${{ secrets.G_TOKEN }}
93-
registry: docker.pkg.github.com
94-
tags: "${{ needs.test.outputs.tag }},${{ steps.create_tag_test.outputs.new_tag }},latest"
95-
- name: Build and Push to DockerHub
96-
uses: elgohr/Publish-Docker-Github-Action@master
99+
# Build
100+
- name: Build and Push image
101+
uses: docker/build-push-action@v2
97102
with:
98-
name: aliaksandrdounar/jelastic-cli
99-
username: ${{ secrets.DOCKER_USERNAME }}
100-
password: ${{ secrets.DOCKER_PASSWORD }}
101-
tags: "${{ needs.test.outputs.tag }},${{ steps.create_tag_test.outputs.new_tag }},latest"
102-
103+
push: true
104+
tags: >
105+
docker.pkg.github.com/${{ needs.test.outputs.repo }}/jelastic-cli:${{ needs.test.outputs.tag }},
106+
docker.pkg.github.com/${{ needs.test.outputs.repo }}/jelastic-cli:${{ steps.create_tag_test.outputs.new_tag }},
107+
docker.pkg.github.com/${{ needs.test.outputs.repo }}/jelastic-cli:latest,
108+
aliaksandrdounar/jelastic-cli:${{ needs.test.outputs.tag }},
109+
aliaksandrdounar/jelastic-cli:${{ steps.create_tag_test.outputs.new_tag }},
110+
aliaksandrdounar/jelastic-cli:latest
103111
release:
104112
name: Create Release
105113
runs-on: ubuntu-latest
106114
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
107-
needs: docker
115+
needs: build
108116
steps:
109-
- name: Checkout code
117+
- name: Checkout Code (Release)
110118
uses: actions/checkout@v2
111-
with:
112-
fetch-depth: 0
113119
- name: Changelog generation
114120
uses: heinrichreimer/[email protected]
115121
id: changelog

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
FROM openjdk:17-alpine3.12
1+
FROM openjdk:16-alpine3.13
22
# Labels
33
LABEL maintainer="[email protected]"
44
# Install Bash, cURL and clean up APK
5-
RUN apk add --no-cache curl==7.69.1-r3 bash==5.0.17-r0 jq==1.6-r1 && \
5+
RUN apk add --no-cache curl=~7.76 bash=~5.1 jq=~1.6 && \
66
rm -vrf /var/cache/apk/*
77
# Create User and Group
88
ENV USER=docker

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ Result JSON document returned from Jelastic.
2424
task: environment/control/getenvs
2525
```
2626
## Local usage
27+
### Information
28+
Docker's entrypoint expects 3+ arguments specified.
29+
```bash
30+
docker run --rm --env JELASTIC_URL --env JELASTIC_USERNAME --env JELASTIC_PASSWORD aliaksandrdounar/jelastic-cli:latest true true environment/control/getenvs
31+
```
32+
Where:
33+
- `true` - login to Jelastic Cloud
34+
- `true` - print json output (instead of raw from the API)
35+
- `environment/control/getenvs` - command
2736
### Preparation
2837
```bash
2938
export JELASTIC_URL=<jelastic_api_fqnd>
@@ -32,10 +41,10 @@ export JELASTIC_PASSWORD=<your_password>
3241
```
3342
### Use from DockerHub
3443
```bash
35-
docker run --rm --env JELASTIC_URL --env JELASTIC_USERNAME --env JELASTIC_PASSWORD aliaksandrdounar/jelastic-cli:latest environment/control/getenvs
44+
docker run --rm --env JELASTIC_URL --env JELASTIC_USERNAME --env JELASTIC_PASSWORD aliaksandrdounar/jelastic-cli:latest true true environment/control/getenvs
3645
```
3746
### Use from GitHub
3847
```bash
3948
echo TOKEN | docker login https://docker.pkg.github.com -u USERNAME --password-stdin
40-
docker run --rm --env JELASTIC_URL --env JELASTIC_USERNAME --env JELASTIC_PASSWORD docker.pkg.github.com/dovnaralexander/jelastic-docker-image/jelastic-cli:latest environment/control/getenvs
49+
docker run --rm --env JELASTIC_URL --env JELASTIC_USERNAME --env JELASTIC_PASSWORD docker.pkg.github.com/dovnaralexander/jelastic-docker-image/jelastic-cli:latest true true environment/control/getenvs
4150
```

action.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ inputs:
1616
jelastic_password:
1717
description: 'Jelastic Password or API Token.'
1818
required: true
19+
login:
20+
description: 'Do you want to login first'
21+
required: false
22+
default: "true"
23+
json:
24+
description: 'Do you want to print jsoned output instead of raw.'
25+
required: false
26+
default: "true"
1927
task:
2028
description: 'Task to execute.'
2129
required: true
@@ -31,4 +39,6 @@ runs:
3139
JELASTIC_USERNAME: ${{ inputs.jelastic_username }}
3240
JELASTIC_PASSWORD: ${{ inputs.jelastic_password }}
3341
args:
42+
- ${{ inputs.login }}
43+
- ${{ inputs.json }}
3444
- ${{ inputs.task }}

entrypoint-github.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ export HOME=/cli # To overwrite GitHub run command
66

77
cd $HOME
88
IFS=" " read -r -a args <<< "$@"
9-
response=$(/cli/entrypoint.sh "${args[@]}" | jq --compact-output)
9+
response=$(/cli/entrypoint.sh "${args[@]}")
1010
echo "::set-output name=output::$response"

entrypoint.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,20 @@
22

33
set -e
44

5-
response=$(echo n | /cli/jelastic/users/authentication/signin --login "$JELASTIC_USERNAME" --password "$JELASTIC_PASSWORD" --platformUrl "$JELASTIC_URL" > /dev/null
6-
/cli/jelastic/"$1" "${@:2}" | sed '/./{H;$!d} ; x ; s/^[^{]*//g' | sed '/./{H;$!d} ; x ; s/[^}]*$//g' | jq
7-
)
5+
login=$1
6+
json=$2
7+
command=$3
8+
home="/cli/jelastic"
9+
10+
if [ "$login" == "true" ]
11+
then
12+
echo n | $home/users/authentication/signin --login "$JELASTIC_USERNAME" --password "$JELASTIC_PASSWORD" --platformUrl "$JELASTIC_URL" > /dev/null
13+
fi
14+
response=$("$home/$command" "${@:3}")
15+
16+
if [ "$json" == "true" ]
17+
then
18+
response=$(echo "$response" | sed -n '1!p' | jq --compact-output || echo "$response")
19+
fi
20+
821
echo "$response"

0 commit comments

Comments
 (0)