-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f3abd8
commit 324acff
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
name: Build and deploy when pushing on staging or main | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- staging | ||
- dev | ||
|
||
env: | ||
IMAGE_NAME: ghcr.io/${{ github.repository }}/albert-spp | ||
IMAGE_TAG: ${{ github.sha }} | ||
application_name: albert-spp | ||
deployment_environment: staging | ||
|
||
jobs: | ||
build-and-push: | ||
name: Build and push from ${{ github.ref_name }}/${{ github.sha }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Log in to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Build and push | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }},${{ env.IMAGE_NAME }}:latest | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
|
||
deploy-dev: | ||
name: Deploy from ${{ github.ref_name }}/${{ github.sha }} | ||
runs-on: ubuntu-latest | ||
needs: build-and-push | ||
if: github.ref_name == 'dev' | ||
steps: | ||
- name: Trigger dev deployment | ||
run: | | ||
RESPONSE="$(curl --request POST \ | ||
--form token=${{ secrets.GITLAB_CI_TOKEN }} \ | ||
--form ref=main \ | ||
--form 'variables[pipeline_name]=${{ github.event.repository.name }}(${{ github.ref_name }}) - ${{ github.event.head_commit.message }}' \ | ||
--form 'variables[docker_image_tag]=${{ env.IMAGE_TAG }}' \ | ||
--form 'variables[application_to_deploy]=${{ env.application_name }}' \ | ||
--form 'variables[deployment_environment]=${{ env.deployment_environment }}' \ | ||
'https://gitlab.com/api/v4/projects/58117805/trigger/pipeline')" | ||
if echo "$RESPONSE" | grep -q '"status":"created"'; then | ||
echo $RESPONSE | ||
echo $RESPONSE | jq -r '.web_url' | ||
else | ||
echo $RESPONSE | ||
exit 1 | ||
fi | ||