Skip to content

Commit

Permalink
refactor(ci): extract ghcr login into separat step
Browse files Browse the repository at this point in the history
  • Loading branch information
ingeridhellen committed Mar 1, 2023
1 parent b1cca70 commit 0d90fe0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/publish-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ jobs:
with:
fetch-depth: 2

- name: "Login to image registry"
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login $IMAGE_REGISTRY -u $GITHUB_ACTOR --password-stdin

- name: "Build and Publish Web"
run: |
echo "Tagging with ${{ inputs.image-tag }}"
echo ${{ secrets.GITHUB_TOKEN }} | docker login $IMAGE_REGISTRY -u $GITHUB_ACTOR --password-stdin
docker pull $WEB_IMAGE
printf "$(git log -n 1 --format=format:'hash: %h%ndate: %cs%nrefs: %d' --decorate=short --decorate-refs=refs/tags | sed 's/ (tag: \([^\s]*\))/\1/')" > ./web/public/version.txt
docker build \
Expand All @@ -58,10 +60,12 @@ jobs:
with:
fetch-depth: 2

- name: "Login to image registry"
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login $IMAGE_REGISTRY -u $GITHUB_ACTOR --password-stdin

- name: "Build and Publish API"
run: |
echo "Tagging with ${{ inputs.image-tag }}"
echo ${{ secrets.GITHUB_TOKEN }} | docker login $IMAGE_REGISTRY -u $GITHUB_ACTOR --password-stdin
docker pull $API_IMAGE
printf "$(git log -n 1 --format=format:'hash: %h%ndate: %cs%nrefs: %d' --decorate=short --decorate-refs=refs/tags | sed 's/ (tag: \([^\s]*\))/\1/')" > ./api/src/version.txt
docker build --cache-from $API_IMAGE --target prod --tag $API_IMAGE ./api
Expand All @@ -72,10 +76,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master

- name: "Login to image registry"
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login $IMAGE_REGISTRY -u $GITHUB_ACTOR --password-stdin

- name: "Build and Publish nginx"
run: |
echo "Tagging with ${{ inputs.image-tag }}"
echo ${{ secrets.GITHUB_TOKEN }} | docker login $IMAGE_REGISTRY -u $GITHUB_ACTOR --password-stdin
docker pull $NGINX_IMAGE
docker build --cache-from $NGINX_IMAGE --tag $NGINX_IMAGE ./nginx
docker tag $NGINX_IMAGE $NGINX_IMAGE:${{ inputs.image-tag }}
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/rollback.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ jobs:
ghcr.io/equinor/template-fastapi-react/nginx,
]
steps:
- uses: actions/checkout@master
- name: "Login to image registry"
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login $IMAGE_REGISTRY -u $GITHUB_ACTOR --password-stdin

- name: "Set prod tag on older image"
run: |
echo "Tagging ${{ matrix.image }}:${{ inputs.release-tag }} with 'production'"
echo ${{ secrets.GITHUB_TOKEN }} | docker login $IMAGE_REGISTRY -u $GITHUB_ACTOR --password-stdin
docker pull ${{ matrix.image }}:${{ inputs.release-tag }}
docker tag ${{ matrix.image }}:${{ inputs.release-tag }} ${{ matrix.image }}:production
docker push $API_IMAGE:production
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ jobs:
steps:
- uses: actions/checkout@master

- name: "Login to image registry"
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login $IMAGE_REGISTRY -u $GITHUB_ACTOR --password-stdin

- name: Build API image
run: |
echo ${{ secrets.GITHUB_TOKEN }} | docker login $IMAGE_REGISTRY -u $GITHUB_ACTOR --password-stdin
docker pull $API_IMAGE
docker build --target development --tag api-development ./api # TODO: --cache-from $API_IMAGE
Expand All @@ -62,9 +64,11 @@ jobs:
steps:
- uses: actions/checkout@master

- name: "Login to image registry"
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login $IMAGE_REGISTRY -u $GITHUB_ACTOR --password-stdin

- name: Build Web Image
run: |
echo ${{ secrets.GITHUB_TOKEN }} | docker login $IMAGE_REGISTRY -u $GITHUB_ACTOR --password-stdin
docker pull $WEB_IMAGE
docker build --cache-from $WEB_IMAGE --target development --tag web-dev ./web
Expand Down

0 comments on commit 0d90fe0

Please sign in to comment.