Skip to content

Commit 9df9207

Browse files
committed
Automate build and deployment with an action
1 parent 3cf293b commit 9df9207

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
on:
2+
push:
3+
branches:
4+
- master
5+
6+
env:
7+
IMAGE_NAME: is-email-disposable
8+
9+
jobs:
10+
build:
11+
name: Build and deploy
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v2
17+
18+
- name: Build image
19+
run: docker build . --file Dockerfile --tag $IMAGE_NAME
20+
21+
- name: Log into registry
22+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
23+
24+
- name: Push image
25+
run: |
26+
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME
27+
28+
# Change all uppercase to lowercase
29+
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
30+
31+
# Strip git ref prefix from version
32+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
33+
34+
# Strip "v" prefix from tag name
35+
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
36+
37+
# Use Docker `latest` tag convention
38+
[ "$VERSION" == "master" ] && VERSION=latest
39+
40+
echo IMAGE_ID=$IMAGE_ID
41+
echo VERSION=$VERSION
42+
43+
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
44+
docker push $IMAGE_ID:$VERSION
45+
46+
- name: Update rancher deployment
47+
uses: th0th/[email protected]
48+
env:
49+
RANCHER_BEARER_TOKEN: ${{ secrets.RANCHER_BEARER_TOKEN }}
50+
RANCHER_CLUSTER_ID: ${{ secrets.RANCHER_CLUSTER_ID }}
51+
RANCHER_NAMESPACE: ${{ secrets.RANCHER_NAMESPACE }}
52+
RANCHER_PROJECT_ID: ${{ secrets.RANCHER_PROJECT_ID }}
53+
RANCHER_URL: ${{ secrets.RANCHER_URL }}
54+
RANCHER_WORKLOADS: ${{ secrets.RANCHER_WORKLOADS }}
55+
56+
- name: Slack notification
57+
uses: 8398a7/action-slack@v3
58+
if: ${{ always() }}
59+
with:
60+
author_name: ${{ github.actor }}
61+
fields: repo,author,message,ref,took,workflow
62+
job_name: Build and deploy
63+
status: ${{ job.status }}
64+
env:
65+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
66+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)