-
Notifications
You must be signed in to change notification settings - Fork 2
57 lines (52 loc) · 1.77 KB
/
build_and_deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
name: Build and push to docker registry when pushing on staging or main
permissions:
packages: write
on:
push:
branches:
- main
- staging
pull_request:
branches:
- main
- dev
jobs:
build-and-push:
environment: ${{ github.ref_name == 'main' && 'prod' || 'staging' }}
name: Build and push from ${{ github.ref_name }}/${{ github.sha }}
runs-on: ubuntu-latest
env:
IMAGE_NAME: ghcr.io/${{ github.repository }}/albert-tchap
IMAGE_TAG: ${{ github.sha }}
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:
push: true
tags: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }},${{ env.IMAGE_NAME }}:latest
deploy-staging:
environment: ${{ github.ref_name == 'main' && 'prod' || 'staging' }}
name: Deploy from ${{ github.ref_name }}/${{ github.sha }}
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/remove_deployment_from_github_actions'
needs: build-and-push
steps:
- name: Trigger staging deployment
run: |
curl --request POST \
--form token=${{ secrets.GITLAB_CI_TOKEN }} \
--form ref=main \
--form "variables[docker_image_tag]=latest" \
--form "variables[application_to_deploy]=albert-tchap" \
--form "variables[deployment_environment]=staging" \
"https://gitlab.com/api/v4/projects/58117805/trigger/pipeline"