add PR cleanup, swap to prod workflows (#121)

This commit is contained in:
Tim Hess 2024-02-09 16:25:23 -06:00 коммит произвёл GitHub
Родитель 567e6ecb40
Коммит 5c75507863
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
7 изменённых файлов: 68 добавлений и 10 удалений

Просмотреть файл

@ -5,3 +5,6 @@ indent_style = space
[*.{js,json}]
indent_size = 2
[*.sh]
end_of_line = lf

Просмотреть файл

@ -1,4 +1,4 @@
name: Build and deploy
name: Build and stage
on:
pull_request:
@ -17,6 +17,7 @@ permissions:
pull-requests: 'write'
env:
IMAGE_NAME: initializr-web
IMAGE_TAG: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || github.run_id }}
jobs:
@ -44,21 +45,21 @@ jobs:
password: "${{ secrets.DOCKER_PASSWORD }}"
- name: Build image
run: docker build . --file "Dockerfile" -t ${{ vars.DOCKER_REGISTRY }}/initializr-web:${{ env.IMAGE_TAG }}
run: docker build . --file "Dockerfile" -t ${{ vars.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
- name: Push image
run: docker push ${{ vars.DOCKER_REGISTRY }}/initializr-web:${{ env.IMAGE_TAG }}
run: docker push ${{ vars.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
- name: If PR, create a new staging slot
if: ${{ github.event_name == 'pull_request' }}
run: az webapp deployment slot create --resource-group ${{ vars.AZURE_RESOURCE_GROUP }} --name ${{ vars.AZURE_WEBAPP_NAME}} --slot ${{ env.SLOT_NAME }} --configuration-source staging
run: az webapp deployment slot create --resource-group ${{ vars.AZURE_RESOURCE_GROUP }} --name ${{ vars.AZURE_WEBAPP_NAME}} --slot ${{ env.SLOT_NAME }} --configuration-source ${{ vars.STAGING_SLOT_NAME }}
- name: Deploy to staging slot
uses: azure/webapps-deploy@v3
id: deploy-to-webapp
with:
app-name: ${{ vars.AZURE_WEBAPP_NAME }}
images: ${{ vars.DOCKER_REGISTRY }}/initializr-web:${{ env.IMAGE_TAG }}
images: ${{ vars.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
slot-name: ${{ env.SLOT_NAME }}
- name: If PR, comment with the preview link

32
.github/workflows/pr-cleanup.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,32 @@
name: Delete a preview environment
on:
pull_request:
types: [closed]
env:
SLOT_NAME: pr-${{ github.event.number }}
jobs:
delete-slot:
runs-on: ubuntu-latest
steps:
- name: Log into Azure CLI with service principal
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Delete slot on staging site
run: az webapp deployment slot delete --resource-group ${{ vars.AZURE_RESOURCE_GROUP }} --name ${{ vars.AZURE_WEBAPP_NAME}} --slot ${{ env.SLOT_NAME }}
delete-deployment:
runs-on: ubuntu-latest
steps:
- name: Delete Deployment Environment
uses: strumwolf/delete-deployment-environment@v2
with:
environment: "pr-${{ github.event.number }}"
token: ${{ secrets.GITHUB_TOKEN }}
onlyRemoveDeployments: true

22
.github/workflows/stage-prod-swap.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,22 @@
name: Swap staging slot contents into production
on:
workflow_dispatch:
jobs:
promote-to-production:
name: Promote to production
runs-on: ubuntu-latest
environment:
name: 'Production'
url: 'https://${{ vars.AZURE_WEBAPP_NAME }}.azurewebsites.net/'
steps:
- name: Log into Azure CLI with service principal
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Swap slots
run: az webapp deployment slot swap -s ${{ vars.STAGING_SLOT_NAME }} -n ${{ vars.AZURE_WEBAPP_NAME }} -g ${{ vars.AZURE_RESOURCE_GROUP }}

2
.mvn/wrapper/maven-wrapper.properties поставляемый
Просмотреть файл

@ -1,2 +1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.2/apache-maven-3.9.5-bin.zip
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.5/apache-maven-3.9.5-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar

Просмотреть файл

@ -25,8 +25,10 @@ RUN echo "env INITIALIZR_SERVICE_HOST;" >> /etc/nginx/main.d/default.conf
RUN echo "env INITIALIZR_SERVICE_URI;" >> /etc/nginx/main.d/default.conf
COPY deploy/docker/initializr-web.conf.template /etc/nginx/templates/
COPY deploy/docker/docker-entrypoint.sh ./
RUN chmod +x docker-entrypoint.sh
RUN chmod +x ./docker-entrypoint.sh
ENTRYPOINT [ "./docker-entrypoint.sh" ]
CMD ["nginx", "-g", "daemon off;"]
# cat /etc/nginx/sites-enabled/initializr.conf
# cat /etc/nginx/sites-enabled/initializr.conf
# tail -f /var/log/nginx/access.log
# tail -f /var/log/nginx/error.log

Просмотреть файл

@ -5,6 +5,4 @@ echo "Starting up with these env variables... host: $INITIALIZR_SERVICE_HOST, ur
envsubst '$INITIALIZR_SERVICE_HOST $INITIALIZR_SERVICE_URI' < /etc/nginx/templates/initializr-web.conf.template > /etc/nginx/sites-enabled/initializr.conf
# cat /etc/nginx/sites-enabled/initializr.conf
exec "$@"