Skip to content

Commit 2f06c62

Browse files
author
Dyakov Roman
authored
CI
1 parent db8a46a commit 2f06c62

1 file changed

Lines changed: 93 additions & 1 deletion

File tree

.github/workflows/build_and_publish.yml

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ name: Build and publish a Docker image
33
on:
44
push:
55
branches: ['main']
6+
tags:
7+
- 'v*'
68

79
env:
810
REGISTRY: ghcr.io
911
IMAGE_NAME: ${{ github.repository }}
1012

1113
jobs:
12-
build-and-push-image:
14+
build-and-push-image-testing:
1315
runs-on: ubuntu-latest
1416
permissions:
1517
contents: read
@@ -31,11 +33,101 @@ jobs:
3133
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
3234
with:
3335
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
36+
tags: |
37+
type=raw,value=test,enable=true
3438
3539
- name: Build and push Docker image
3640
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
3741
with:
3842
context: .
3943
push: true
44+
build-args: |
45+
BUILD_MODE=development
4046
tags: ${{ steps.meta.outputs.tags }}
4147
labels: ${{ steps.meta.outputs.labels }}
48+
49+
build-and-push-image-production:
50+
runs-on: ubuntu-latest
51+
if: startsWith(github.ref, 'refs/tags/v')
52+
permissions:
53+
contents: read
54+
packages: write
55+
56+
steps:
57+
- name: Checkout repository
58+
uses: actions/checkout@v2
59+
60+
- name: Log in to the Container registry
61+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
62+
with:
63+
registry: ${{ env.REGISTRY }}
64+
username: ${{ github.actor }}
65+
password: ${{ secrets.GITHUB_TOKEN }}
66+
67+
- name: Extract metadata (tags, labels) for Docker
68+
id: meta
69+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
70+
with:
71+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
72+
tags: |
73+
type=ref,event=tag,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
74+
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
75+
76+
- name: Build and push Docker image
77+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
78+
with:
79+
context: .
80+
push: true
81+
build-args: |
82+
BUILD_MODE=production
83+
tags: ${{ steps.meta.outputs.tags }}
84+
labels: ${{ steps.meta.outputs.labels }}
85+
86+
deploy-testing:
87+
name: Deploy Testing
88+
needs: build-and-push-image-testing
89+
runs-on: [self-hosted, Linux]
90+
environment:
91+
name: Testing
92+
url: https://printer.ui.test.profcomff.com/
93+
env:
94+
CONTAITER_NAME: com_profcomff_ui_printer_test
95+
permissions:
96+
packages: read
97+
98+
steps:
99+
- name: Run docker container
100+
run: |
101+
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test
102+
docker stop ${{ env.CONTAITER_NAME }} || true && docker rm ${{ env.CONTAITER_NAME }} || true
103+
docker run \
104+
--detach \
105+
--restart on-failure:3 \
106+
--network=web \
107+
--name ${{ env.CONTAITER_NAME }} \
108+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test
109+
110+
deploy-production:
111+
name: Deploy Production
112+
needs: build-and-push-image-production
113+
if: startsWith(github.ref, 'refs/tags/v')
114+
runs-on: [self-hosted, Linux]
115+
environment:
116+
name: Production
117+
url: https://printer.ui.profcomff.com/
118+
env:
119+
CONTAITER_NAME: com_profcomff_ui_printer
120+
permissions:
121+
packages: read
122+
123+
steps:
124+
- name: Run docker container
125+
run: |
126+
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
127+
docker stop ${{ env.CONTAITER_NAME }} || true && docker rm ${{ env.CONTAITER_NAME }} || true
128+
docker run \
129+
--detach \
130+
--restart always \
131+
--network=web \
132+
--name ${{ env.CONTAITER_NAME }} \
133+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest

0 commit comments

Comments
 (0)