Skip to content

Commit 156ac18

Browse files
authored
Merge pull request #1314 from corbanvilla/master
Automated docker builds
2 parents 16b756f + b2e3a36 commit 156ac18

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed

.dockerignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Ignore target directory
2+
target/
3+
4+
# Ignore any build artifacts
5+
**/*.rs.bk
6+
7+
# Ignore any generated files
8+
**/Cargo.lock
9+
**/Cargo.toml.orig
10+
**/Cargo.toml.bk
11+
12+
# Ignore any IDE-specific files
13+
.vscode/
14+
.idea/
15+
16+
# Ignore Dockerfile and dockerignore file
17+
Dockerfile
18+
.dockerignore
19+
20+
# Workflow
21+
.github

.github/workflows/docker.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Docker Image CI
2+
3+
on:
4+
push:
5+
branches: [ '*' ]
6+
7+
env:
8+
IMAGE_NAME: rusty
9+
10+
jobs:
11+
# Push image to GitHub Packages.
12+
# See also https://docs.docker.com/docker-hub/builds/
13+
build-linux:
14+
runs-on: ${{ matrix.config.os }}
15+
strategy:
16+
matrix:
17+
config:
18+
- {
19+
os: "ubuntu-latest",
20+
version: "linux",
21+
arch: "x86_64"
22+
}
23+
permissions:
24+
packages: write
25+
contents: read
26+
27+
steps:
28+
- uses: actions/checkout@v3
29+
30+
- name: Build image
31+
shell: bash
32+
run: docker buildx build . --platform ${{matrix.config.version}}/${{matrix.config.arch}} --file Dockerfile --tag $IMAGE_NAME
33+
34+
- name: Log in to registry
35+
if: ${{ github.event_name != 'pull_request' }}
36+
# This is where you will update the PAT to GITHUB_TOKEN
37+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
38+
39+
- name: Push image
40+
shell: bash
41+
if: ${{ github.event_name != 'pull_request' }}
42+
run: |
43+
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
44+
45+
# Extract branch name
46+
BRANCH_NAME=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
47+
48+
# Append branch name to image ID
49+
IMAGE_ID=$IMAGE_ID-$BRANCH_NAME
50+
51+
# Change all uppercase to lowercase
52+
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
53+
54+
# Strip git ref prefix from version
55+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
56+
57+
# Use Docker `latest` tag convention
58+
[ "$VERSION" == "main" ] && VERSION=latest
59+
#Add the platform to the version
60+
VERSION=$VERSION-${{ matrix.config.arch }}
61+
echo IMAGE_ID=$IMAGE_ID
62+
echo VERSION=$VERSION
63+
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
64+
docker push $IMAGE_ID:$VERSION
65+
66+
push-multiplatform:
67+
name: Push multi platform
68+
needs: build-linux
69+
runs-on: ubuntu-latest
70+
if: ${{ github.event_name != 'pull_request' }}
71+
steps:
72+
- name: Log in to registry
73+
if: ${{ github.event_name != 'pull_request' }}
74+
# This is where you will update the PAT to GITHUB_TOKEN
75+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
76+
77+
- name: Get images
78+
shell: bash
79+
run: |
80+
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
81+
82+
# Change all uppercase to lowercase
83+
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
84+
# Strip git ref prefix from version
85+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
86+
# Strip "v" prefix from tag name
87+
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
88+
# Use Docker `latest` tag convention
89+
[ "$VERSION" == "main" ] && VERSION=latest
90+
docker manifest create $IMAGE_ID:$VERSION $IMAGE_ID:$VERSION-arm64 $IMAGE_ID:$VERSION-x86_64
91+
docker manifest push $IMAGE_ID:$VERSION

Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM ghcr.io/plc-lang/rust-llvm:latest
2+
3+
# Allow invoking `plc` from anywhere
4+
ENV PLCLOC="/opt/rusty"
5+
ENV STDLIBLOC="/opt/rusty/stdlib"
6+
ENV PATH="${PLCLOC}:${PATH}"
7+
8+
# Give all users access to cargo and rust home
9+
RUN chmod -R a+rw $CARGO_HOME \
10+
&& chmod -R a+rw $RUSTUP_HOME
11+
12+
# Required if we want to use `lld` as the default linker for RuSTy
13+
ENV LLVM_VER=14
14+
RUN ln -sf /usr/bin/ld.lld-$LLVM_VER /usr/bin/ld.lld
15+
16+
# Install the local RuSTy version
17+
WORKDIR /rusty
18+
COPY . .
19+
RUN ./scripts/build.sh --build --release --package
20+
RUN mkdir -p ${PLCLOC} && \
21+
cp /rusty/target/release/plc ${PLCLOC}
22+
RUN mkdir -p ${STDLIBLOC} && \
23+
cp -r /rusty/output/* ${STDLIBLOC}
24+
25+
ENTRYPOINT [ "/bin/bash", "-c" ]
26+
CMD ["plc", "--help"]

0 commit comments

Comments
 (0)