Skip to content

Commit c93c4c5

Browse files
authored
Merge pull request #9 from marianzarg/feature
Feature
2 parents 8a12575 + 2783884 commit c93c4c5

File tree

8 files changed

+118
-0
lines changed

8 files changed

+118
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/token.txt

github-packages/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM alpine:latest
2+
CMD echo "Hello World!!"
3+
CMD echo "Hola Ivan"

github-packages/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Usage
2+
3+
Replace token.txt 2nd line with GitHub PAT Token

github-packages/create.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
source variables.sh
3+
4+
echo ""
5+
echo "Docker build image"
6+
docker build -q -t $GH_IMAGE_NAME .
7+
echo "#################"
8+
9+
echo ""
10+
echo "Docker Login"
11+
echo $GH_TOKEN | docker login ghcr.io -u $GH_USERNAME --password-stdin
12+
echo "#################"
13+
14+
echo ""
15+
echo "Image name | Tag name"
16+
echo "$GH_IMAGE_NAME $GH_TAG_NAME"
17+
echo "#################"
18+
19+
echo ""
20+
echo "Create a docker tag"
21+
docker tag $GH_IMAGE_NAME $GH_TAG_NAME
22+
echo "#################"
23+
24+
echo ""
25+
echo "Push docker tag"
26+
docker push $GH_TAG_NAME
27+
echo "#################"
28+
29+
echo ""
30+
echo "Remove local image"
31+
docker image rm -f $GH_IMAGE_NAME $GH_TAG_NAME
32+
echo "#################"
33+
34+
echo ""
35+
echo "Print Docker image ls"
36+
docker image ls gh
37+
echo "#################"
38+
39+
echo ""
40+
echo "Clean Environment Variables"
41+
unset GH_TAG_NAME
42+
unset GH_IMAGE_NAME
43+
unset GH_VER
44+
unset GH_TOKEN
45+
unset GH_USERNAME
46+
echo "#################"
47+
48+
echo ""
49+
echo "Print Clean ENV"
50+
env | grep GH
51+
echo "#################"
52+
53+
echo ""
54+
echo "Logout ghcr.io"
55+
docker logout ghcr.io
56+
echo "################"

github-packages/delete.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
source variables.sh
3+
version_id=""
4+
5+
# Prompt the user for input and store it in 'flag'
6+
while true; do
7+
read -p "Enter the flag (e.g., 'package (p)' or 'version(v)'): " flag
8+
# Convert the input to lowercase
9+
flag="${flag,,}"
10+
11+
# Check if the flag is either "package" or "version"
12+
if [[ "$flag" == "package" || "$flag" == "p" || "$flag" == "version" || "$flag" == "v" ]]; then
13+
break
14+
else
15+
echo "Invalid input. Please enter 'package', 'p' or 'version', 'v'."
16+
fi
17+
done
18+
19+
20+
# Convert the input to lowercase using parameter expansion
21+
flag="${flag,,}"
22+
23+
if [[ "$flag" == "package" || "$flag" == "p" ]]
24+
then
25+
echo "Opción $flag"
26+
curl -X DELETE \
27+
-H "Authorization: Bearer $GH_TOKEN" \
28+
-H "Accept: application/vnd.github+json" \
29+
"https://api.github.com/users/$GH_USERNAME/packages/container/$GH_IMAGE_NAME"
30+
else
31+
echo "Opción $flag"
32+
33+
read -p "Enter version_id: " version_id
34+
echo $version_id
35+
36+
curl -X DELETE \
37+
-H "Authorization: Bearer $GH_TOKEN" \
38+
-H "Accept: application/vnd.github+json" \
39+
"https://api.github.com/users/$GH_USERNAME/packages/container/$GH_IMAGE_NAME/versions/$version_id"
40+
fi

github-packages/get.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
source variables.sh
3+
4+
curl -H "Authorization: Bearer $GH_TOKEN" \
5+
-H "Accept: application/vnd.github+json" \
6+
"https://api.github.com/users/$GH_USERNAME/packages/container/$GH_IMAGE_NAME/versions"

github-packages/token.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#Add PAT Token for GitHub in 2nd line.
2+
<<insert token here>>

github-packages/variables.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
echo "Source variables.sh"
3+
export GH_USERNAME="marianzarg"
4+
export GH_TOKEN=$(sed -n '2p' token.txt)
5+
export GH_VER="3.0.0"
6+
export GH_IMAGE_NAME="hello-world-gh-packages"
7+
export GH_TAG_NAME="ghcr.io/$GH_USERNAME/$GH_IMAGE_NAME:$GH_VER"

0 commit comments

Comments
 (0)